Daily bit(e) of C++ | std::function
Daily bit(e) of C++ ♻️143, Storing different callable objects in the std::function container.
std::function is a storage type that can store callable entities (functions, function objects, lambdas) that conform to the specified call signature.
The container is copyable (which it also requires of the wrapped object) and will throw when invoked without a stored state.
std::function can be used as a type-erasure tool since it hides the actual type of the wrapped callable. However, because of its many downsides, consider more modern alternatives (C++23 std::move_only_function).