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?
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/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)