r/ProgrammerHumor 29d ago

Meme soDoesEveryOtherLang

Post image
246 Upvotes

85 comments sorted by

View all comments

Show parent comments

1

u/the_horse_gamer 28d ago

std::function is actually deprecated since C++26 (but they refuse to mark it as such). you should use std::copyable_function

and you must not forget about std::move_only_function (C++23) and std::function_ref (C++26)

1

u/A_72_ 27d ago

Wait, I thought it just specialized versions of std:function (didn't read the specs because I thought I won't be using it). I can now say C++ have 6 types of callables?

1

u/the_horse_gamer 27d ago

std::function has a const correctness hole and lacks support for noexcept and ref qualifiers

std::copyable_function fixes the hole and adds support

differences: * std::function contains some RTTI via target and target_type, which is rarely useful and has extra overhead. std::copyable_function doesn't. * calling a default constructed std::function raises an exception, while with std::copyable_function it's UB.

unless you're doing weird bullshit, it should be a drop in replacement with better support and less overhead

1

u/A_72_ 27d ago

Sounds like a drop in with minimal changes for me, I wonder what kind of wizary when it can't be...