A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.
Document number: N3974
Date: 2014-05-28
Polymorphic Deleter for Unique Pointers
by Marco Arena, Davide di Gennaro and Peter Sommerlad
Excerpt:
... However, with heap-allocated polymorphic types in C++11 code this means one needs to use
shared_ptr<Base>
andmake_shared<Derived>
to avoid the need to define a virtual destructor forBase
. There is no standard deleter forunique_ptr
that will allow to safely useunique_ptr<Base>
ifBase
doesn't define a virtual destructor. Such a misuse is not even detectable easily. However, always usingshared_ptr
to get its desired deleter magic would also incur the overhead of the atomic reference counter and the overhead of full type erasure.This proposal tries to ease the burden for programmers of heap allocated polymorphic classes and gives them the option to use
unique_ptr
with a standard provided deleter classes that either check correct provisioning of a virtual destructor in the base class or provide a slight overhead infrastructure for safe deletes through base type pointers, even if the base class doesn't define a virtual destructor.
Add a Comment
Comments are closed.