Jun 9, 2014

[C++11] auto , lambda and proxy object


auto fun = []{}; // 1

function<void()> fun = []{}; // 2

Difference:

1.
Will be on stack.
Will most likely inlined.

2.
Will be on heap or stack, depends on the size of lambda.


Do not use auto with proxy object. e.g :

// b is St14_Bit_reference type, not bool, and point to a dangling ptr.
auto b = vector<bool>({1,0,0})[1];

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.