lambda constness?
c++0x supports lambdas that capture values by reference:
[&] -> ret_t { return 0; }
Does it make sense to capture const references?
[const &] -> ret_t { return 0; }
More fundamentally to the question at hand; is there a way to detect if a given lam开发者_开发百科bda being passed as a std::function<>
is free of side-effects?
You can't even guarantee that what's in a std::function
is a lambda or not. You certainly can't guarantee that it has no side effects.
If you want to ensure that the lambda function you write doesn't have side effects (to the extent that such things can be ensured), the only way to do that is to capture nothing: []
.
精彩评论