lurscher
lurscher

Reputation: 26943

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 lambda being passed as a std::function<> is free of side-effects?

Upvotes: 3

Views: 342

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473322

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

Upvotes: 2

Related Questions