There are
std::function_ref
(or std::move_only_function
) that can be used instead of std::function
to accept non-copyable types. But those are fairly new, C++26 and C++23 respectively.