20 Memory management library [mem]

20.4 Types for composite class design [mem.composite.types]

20.4.2 Class template polymorphic [polymorphic]

20.4.2.1 General [polymorphic.general]

A polymorphic object manages the lifetime of an owned object.
A polymorphic object may own objects of different types at different points in its lifetime.
A polymorphic object is valueless if it has no owned object.
A polymorphic object may become valueless only after it has been moved from.
In every specialization polymorphic<T, Allocator>, if the type allocator_traits<Allocator>​::​value_type is not the same type as T, the program is ill-formed.
Every object of type polymorphic<T, Allocator> uses an object of type Allocator to allocate and free storage for the owned object as needed.
Constructing an owned object of type U with args... using the allocator a means calling allocator_traits<Allocator>​::​cop, args...) where args is an expression pack, a is an allocator, and p points to storage suitable for an owned object of type U.
The member alloc is used for any memory allocation and element construction performed by member functions during the lifetime of each polymorphic value object, or until the allocator is replaced.
The allocator may be replaced only via assignment or swap().
Allocator replacement is performed by copy assignment, move assignment, or swapping of the allocator only if ([container.reqmts]):
  • allocator_traits<Allocator>​::​propagate_on_container_copy_assignment​::​value, or
  • allocator_traits<Allocator>​::​propagate_on_container_move_assignment​::​value, or
  • allocator_traits<Allocator>​::​propagate_on_container_swap​::​value
is true within the implementation of the corresponding polymorphic operation.
A program that instantiates the definition of polymorphic for a non-object type, an array type, in_place_t, a specialization of in_place_type_t, or a cv-qualified type is ill-formed.
The template parameter T of polymorphic may be an incomplete type.
The template parameter Allocator of polymorphic shall meet the requirements of Cpp17Allocator.
If a program declares an explicit or partial specialization of polymorphic, the behavior is undefined.