#why std::move_only_function and std::copyable_function
20 messages · Page 1 of 1 (latest)
When your question is answered use !solved or the button below to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
std::function can only accept functions that are themselves copyable. If yours is move-only, you're out of luck
std::move_only_function can accept those, but is itself not copyable
std::copyable_function is basically std::function 2.0
why is that
You mean why rewrite std::function?
can you give an example of a move-only function? i assume it has to be a lambda or functor of some form or shape
yes
Yeah. E.g. a lambda that captures a std::unique_ptr
ah ok that makes sense i hadn't thought about lambda with unique ptr
If you're asking about std::copyable_function, then apparently they made it to fix some issues that std::function had. At least one of them is that it's not const-correct, i.e. its operator() is const, but it can call a non-const () on the underlying function
std::move_only_function also had this fix, so it makes sense to have them consistent
and they made another one instead of fixing std::function because ABI blah blah ?