Peter Milley Peter Milley - 18 days ago 7
C++ Question

Why is std::function itself a copy-constructible type?

I've found the tr.func.require section of the specification that requires

std::function
to be copy-constructable in C++11, and I've seen plenty of explanations of why this implies that the functors used to construct
std::function
have to be copyable, but why did the C++11 standard made
std::function
copyable in the first place, instead of making it a move-only type?

Answer

std::function was implemented before C++11 when move-semantics were not yet available (it stems from boost::function and was part of TR1).

My guess is that std::function was specified (and perhaps voted into the standard) before move semantics. And the didn't have time to review all the rest of the standard in light of this. See also this answer about why shared_ptr deleters have to be CopyConstructible.

Also, for compatibility reasons, it sounds unreasonable to all-of-a-sudden make std::function move constructible and remove its copy-constructor.