I am reading \"Effective Modern C++\". In the item related to std::unique_ptr
it\'s stated that if the custom deleter is a stateless object, then no size fees o
If the deleter is stateless there's no space required to store it. If the deleter is not stateless then the state needs to be stored in the unique_ptr
itself.
std::function
and function pointers have information that is only available at runtime and so that must be stored in the object alongside the pointer the object itself. This in turn requires allocating (in the unique_ptr
itself) space to store that extra state.
Perhaps understanding the Empty Base Optimization will help you understand how this could be implemented in practice.
The std::is_empty type trait is another possibility of how this could be implemented.
How exactly library writers implement this is obviously up to them and what the standard allows.