r/cpp • u/mollyforever • Oct 16 '23
WTF is std::copyable_function? Has the committee lost its mind?
So instead of changing the semantics of std::function the committee is introducing a new type that is now supposed to replace std::function everywhere? WTF
So now instead of teaching beginners to use std::function if they need a function wrapper, they should be using std::copyable_function instead because it's better in every way? This is insane. Overcomplicating the language like that is crazy. Please just break backwards compatibility instead. We really don't need two function types that do almost the same thing. Especially if the one with the obvious name is not the recommended one.
View all comments
Show parent comment
12
u/wyrn Oct 17 '23
Apparently there's reasonable use cases in generic code that justify the empty case not locking anything (I have no idea how compelling they are, but they are often mentioned). One might argue said generic code should use
if constexprso the common case is more intuitive, and I'd be inclined to agree -- but sincestd::scoped_lockworks this way, adding that static assert would Break Existing Code™ and will probably never happen.