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.3 Constructors [polymorphic.ctor]

The following element applies to all functions in [polymorphic.ctor]:
Throws: Nothing unless allocator_traits<Allocator>​::​allocate or allocator_traits<Allocator>​::​construct throws.
constexpr explicit polymorphic();
Constraints: is_default_constructible_v<Allocator> is true.
Mandates:
  • is_default_constructible_v<T> is true, and
  • is_copy_constructible_v<T> is true.
Effects: Constructs an owned object of type T with an empty argument list using the allocator alloc.
constexpr explicit polymorphic(allocator_arg_t, const Allocator& a);
Mandates:
  • is_default_constructible_v<T> is true, and
  • is_copy_constructible_v<T> is true.
Effects: alloc is direct-non-list-initialized with a.
Constructs an owned object of type T with an empty argument list using the allocator alloc.
constexpr polymorphic(const polymorphic& other);
Effects: alloc is direct-non-list-initialized with allocator_traits<Allocator>​::​select_on_container_copy_construction(other.alloc).
If other is valueless, *this is valueless.
Otherwise, constructs an owned object of type U, where U is the type of the owned object in other, with the owned object in other using the allocator alloc.
constexpr polymorphic(allocator_arg_t, const Allocator& a, const polymorphic& other);
Effects: alloc is direct-non-list-initialized with a.
If other is valueless, *this is valueless.
Otherwise, constructs an owned object of type U, where U is the type of the owned object in other, with the owned object in other using the allocator alloc.
constexpr polymorphic(polymorphic&& other) noexcept;
Effects: alloc is direct-non-list-initialized with std​::​move(other.alloc).
If other is valueless, *this is valueless.
Otherwise, either *this takes ownership of the owned object of other or, owns an object of the same type constructed from the owned object of other considering that owned object as an rvalue, using the allocator alloc.
constexpr polymorphic(allocator_arg_t, const Allocator& a, polymorphic&& other) noexcept(allocator_traits<Allocator>::is_always_equal::value);
Effects: alloc is direct-non-list-initialized with a.
If other is valueless, *this is valueless.
Otherwise, if alloc == other.alloc is true, either constructs an object of type polymorphic that owns the owned object of other, making other valueless; or, owns an object of the same type constructed from the owned object of other considering that owned object as an rvalue.
Otherwise, if alloc != other.alloc is true, constructs an object of type polymorphic, considering the owned object in other as an rvalue, using the allocator alloc.
template<class U = T> constexpr explicit polymorphic(U&& u);
Constraints: Where UU is remove_cvref_t<U>,
  • is_same_v<UU, polymorphic> is false,
  • derived_from<UU, T> is true,
  • is_constructible_v<UU, U> is true,
  • is_copy_constructible_v<UU> is true,
  • UU is not a specialization of in_place_type_t, and
  • is_default_constructible_v<Allocator> is true.
Effects: Constructs an owned object of type U with std​::​forward<U>(u) using the allocator alloc.
template<class U = T> constexpr explicit polymorphic(allocator_arg_t, const Allocator& a, U&& u);
Constraints: Where UU is remove_cvref_t<U>,
  • is_same_v<UU, polymorphic> is false,
  • derived_from<UU, T> is true,
  • is_constructible_v<UU, U> is true,
  • is_copy_constructible_v<UU> is true, and
  • UU is not a specialization of in_place_type_t.
Effects: alloc is direct-non-list-initialized with a.
Constructs an owned object of type U with std​::​forward<U>(u) using the allocator alloc.
template<class U, class... Ts> constexpr explicit polymorphic(in_place_type_t<U>, Ts&&... ts);
Constraints:
  • is_same_v<remove_cvref_t<U>, U> is true,
  • derived_from<U, T> is true,
  • is_constructible_v<U, Ts...> is true,
  • is_copy_constructible_v<U> is true, and
  • is_default_constructible_v<Allocator> is true.
Effects: Constructs an owned object of type U with std​::​forward<Ts>(ts)... using the allocator alloc.
template<class U, class... Ts> constexpr explicit polymorphic(allocator_arg_t, const Allocator& a, in_place_type_t<U>, Ts&&... ts);
Constraints:
  • is_same_v<remove_cvref_t<U>, U> is true,
  • derived_from<U, T> is true,
  • is_constructible_v<U, Ts...> is true, and
  • is_copy_constructible_v<U> is true.
Effects: alloc is direct-non-list-initialized with a.
Constructs an owned object of type U with std​::​forward<Ts>(ts)... using the allocator alloc.
template<class U, class I, class... Us> constexpr explicit polymorphic(in_place_type_t<U>, initializer_list<I> ilist, Us&&... us);
Constraints:
  • is_same_v<remove_cvref_t<U>, U> is true,
  • derived_from<U, T> is true,
  • is_constructible_v<U, initializer_list<I>&, Us...> is true,
  • is_copy_constructible_v<U> is true, and
  • is_default_constructible_v<Allocator> is true.
Effects: Constructs an owned object of type U with the arguments ilist, std​::​forward<Us>(us)... using the allocator alloc.
template<class U, class I, class... Us> constexpr explicit polymorphic(allocator_arg_t, const Allocator& a, in_place_type_t<U>, initializer_list<I> ilist, Us&&... us);
Constraints:
  • is_same_v<remove_cvref_t<U>, U> is true,
  • derived_from<U, T> is true,
  • is_constructible_v<U, initializer_list<I>&, Us...> is true, and
  • is_copy_constructible_v<U> is true.
Effects: alloc is direct-non-list-initialized with a.
Constructs an owned object of type U with the arguments ilist, std​::​forward<Us>(us)... using the allocator alloc.