I'm passing a lambda to a function which accepts it as a r-value reference.
If my lambda is defined in the function-call itself, I don't really care what happens to it later.
But if my lambda is a variable (say I want to use it more than once) I do want to know that it is not moved-from.
Is there a way to know will it be moved-from or not, making it unusable or usable accordingly after the call has returned?
Well, if the function accept a universal reference and you want to forbid moving, there are many options for you to choose from, among others:
- Pass by constant reference (C++17 has
std::as_const()to simplify that).
- Save it as a local and don't convert to rvalue-reference. Seems you do that.
- Use something to explicitly convert an rvalue-reference to an lvalue-reference.
Of course, if none of the variables captured by value by the lambda have different move-semantics than copy-semantics, the point is moot.