开发者

lambda constness?

开发者 https://www.devze.com 2023-04-12 03:00 出处:网络
c++0x supports lambdas that capture values by reference: [&] -> ret_t { return 0; } Does it make sense to capture const references?

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: [].

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号