c++ - Understanding Move Capture in Lambdas for C++11 -
i have question regarding workaround proposed in order address move capture in c++11 lambdas. in particular, taking example meyer's book:
std::vector<double> data; ... auto func = std::bind( [](const std::vector<double>& data) { /*uses of data*/ }, std::move(data) );
my question is: consequences/meaning of declaring parameter "data" rvalue reference?:
auto func = std::bind( [](std::vector<double>&& data) ...
to guide answer, i'll make 3 claims. please tell me if i'm right or wrong:
- in both cases, move capture semantics included in c++14 emulated.
- in both cases, not safe use data after definition of "func".
- the difference in second case (rvalue reference), stating callable object (the lambda) move contents of "data".
thanks in advance.
what consequences/meaning of declaring parameter "
data
" rvalue reference?
it won't compile (at least if attempt call func
). std::bind
pass bound arguments lvalues, won't bind rvalue reference.
in both cases, not safe use data after definition of "func".
data
left in valid unspecified state move. can use same way use vector contents unknown.
Comments
Post a Comment