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 occur, but if it's a function pointer or std::function
size fee occurs. Could you explain why?
Let's say that we have the following code:
auto deleter_ = [](int *p) { doSth(p); delete p; };
std::unique_ptr<int, decltype(deleter_)> up(new int, deleter_);
To my understanding, the unique_ptr
should have an object of type decltype(deleter_)
and assign deleter_
to that internal object. But obviously that's not what's happening. Could you explain the mechanism behind this using smallest possible code example?