I've noticed that when I use std::shared_ptr
(or any other smart pointer) a custom allocator/deleter is assigned through the ctor, which happens to be a template. My question is: how is the allocator/deleter stored and used?
Are these functors stored as a function pointer, void*
, or what? Is it an indirect call, or a direct call?
Just to have more of a clear understanding of what I'm trying to ask, consider the following code:
struct SomethingAwesomeDeleter
{
public:
void operator()(SomethingAwesome* ptr) const
{
// do something awesome
delete ptr;
}
};
typedef std::shared_ptr<SomethingAwesome> SomethingAwesomePtr;
SomethingAwesomePtr ptr{new SomethingAwesome, SomethingAwesomeDeleter{}};
How is SomethingAwesomeDeleter{}
stored and used?
NOTE:
I do realise std::shared_ptr
is a template class, however std::shared_ptr
does not have template arguments for the deleter/allocator in the class template arguments, i.e. there is no such template class as std::shared_ptr<T, Allocator, Deleter>
.