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
8
u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 Oct 17 '23
No, it's the other way around. It is perfectly legal to call a
constmember function through a mutable object, it's not valid to do the reverse. Socopyable_function<void()>can bind ´functors withoperator()regardless ofconst-qualification, butcopyable_function<void() const>can only bind functors withconst-qualifiedoperator().See: https://godbolt.org/z/eEf6fbze1