开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜