As I understand the problem, the goal is that when you delete the last shared pointer to a resource, the resource must be removed from the ResourceMap and then deleted. As you say, this is not possible if the shared resource pointer is stored in the ResourceMap, since the shared map pointer will always be the last shared resource pointer.
, . - (std::weak_ptr) . , , ResourceMap. std::map ( std::unordered_map), , mapped_type .
map map::emplace.
ResourceDeleter , , ( ). ( shared_ptr) .
shared_ptr, shared_pointer std::pair<const key_type, mapped_type>. , * p->second, *p.