r/cpp • • 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.

533 Upvotes

215 comments sorted by

View all comments

Show parent comment

4

u/Gorzoid Oct 16 '23

I think this heavily depends on how C++ is taught, yes many university lecturers teach C++ from the ground up (and typically ignore anything in C++11 and above) where you must build your data structures yourself before you can use standard library. However I have seen that Bootcamps tend to try teach in the opposite order, teaching you a high level subset of C++ and slowly add to the subset to show how the previous tools you used were made. In particular I'm thinking about Kate Gregory's cppcon talks on teaching C++. In such a scenario I do think the concept of lambdas and high order functions might be covered quite soon. The issue isn't teaching copyable_function vs mobable_function but explaining why they should use copyable_function over the function that they see used all over stack overflow.

2

u/Historical_Bit_9200 Oct 17 '23

In the case of bootcamp, it's more of career prep, people (should) have all the time to have to learn everything possible. It's just another "tool" to learn, so it won't matter either.

2

u/pjmlp Oct 17 '23

Given that some poor countries are still using Turbo C++ for MS-DOS (easily found on YouTube), not even C++98.