jeudi 26 décembre 2019

Capture arguments are copied from rvalue lambda? [duplicate]

This question already has an answer here:

Are captured arguments copied during the conversion of lambdas to std::function?
I need to convert a lambda that captures a non-copyable type to std::function.
So I passed a lambda to std::function as an rvalue, but an error occurred.

// Foo is non-copyable.
auto a = [f = Foo()]{ };
std::function<void()> b = std::move(a) // error, calls deleted Foo::Foo(const Foo&);

Aucun commentaire:

Enregistrer un commentaire