ISO/IEC JTC1 SC22 WG21 P0942R0
Jens Maurer <Jens.Maurer@gmx.net>
Target audience: LEWG, LWG
2018-02-10

P0942R0: Introducing a <smart_ptr> header

Introduction

The current <memory> header has a mix of tools for two widely different audiences: It was a mistake to mix tools for these two audiences in a single header. I therefore suggest to introduce a new header <smart_ptr> where all the smart pointers live. For backward compatibility, <memory> must include <smart_ptr>.

Discussion

This has been raised in passing several times, so here is the paper that actually does it.

Regarding feature testing, checking for the presence of the <smart_ptr> header suffices.

Wording

Add <smart_ptr> to table 16 in subclause 20.5.1.2 [headers].

Create a new first subclause [smart_ptr.syn] under 23.11 [smartptr]:

The header <smart_ptr> defines several smart pointer types and various function templates that operate on objects of these types.
Move all declarations for entities described in [smartptr] from [memory.syn] to [smart_ptr.syn]:
// 23.11.1, class template unique_ptr
template<class T> struct default_delete;
template<class T> struct default_delete<T[]>;
...
// 23.11.8, atomic smart pointers
template<class T> struct atomic<shared_ptr<T>>;
template<class T> struct atomic<weak_ptr<T>>;
 
Change 23.10.2 [memory.syn] paragraph 1 as follows:
The header <memory> defines several types and function templates that describe properties of pointers and pointer-like types, manage memory for containers and other template types, destroy objects, and construct multiple objects in uninitialized memory buffers (23.10.3-23.10.11). The header also defines the templates unique_ptr, shared_ptr, weak_ptr, and various function templates that operate on objects of these types (23.11).
Add a new subclause in Annex D [depr]:
D.x Deprecated location of smart pointers [depr.memory.smartptr]

The header <memory> has the following addition:

  #include <smart_ptr>