std::polymorphic<T, Allocator>::polymorphic - cppreference.com (original) (raw)

constexpr explicit polymorphic(); (1) (since C++26)
constexpr explicit polymorphic( std::allocator_arg_t, const Allocator& a ); (2) (since C++26)
template< class U = T > constexpr explicit polymorphic( U&& v ); (3) (since C++26)
template< class U = T > constexpr explicit polymorphic( std::allocator_arg_t, const Allocator& a, U&& v ); (4) (since C++26)
template< class U, class... Args > constexpr explicit polymorphic( std::in_place_type_t<U>, Args&&... args ); (5) (since C++26)
template< class U, class... Args > constexpr explicit polymorphic( std::allocator_arg_t, const Allocator& a, std::in_place_type_t<U>, Args&&... args ); (6) (since C++26)
template< class U, class I, class... Args > constexpr explicit polymorphic( std::in_place_type_t<U>, std::initializer_list<I> ilist, Args&&... args ); (7) (since C++26)
template< class U, class I, class... Args > constexpr explicit polymorphic( std::allocator_arg_t, const Allocator& a, std::in_place_type_t<U>, std::initializer_list<I> ilist, Args&&... args ); (8) (since C++26)
constexpr polymorphic( const polymorphic& other ); (9) (since C++26)
constexpr polymorphic( std::allocator_arg_t, const Allocator& a, const polymorphic& other ); (10) (since C++26)
constexpr polymorphic( polymorphic&& other ) noexcept; (11) (since C++26)
constexpr polymorphic( std::allocator_arg_t, const Allocator& a, polymorphic&& other ) noexcept(/* see below */); (12) (since C++26)

Constructs a new polymorphic object.

Contents

[edit] Parameters

a - the allocator to be associated
v - value with which to initialize the owned value
args - arguments with which to initialize the owned value
il - initializer list with which to initialize the owned value
other - another polymorphic object whose owned value (if exists) is copied

[edit] Effects

The construction of a new polymorphic object consists of the following steps:

  1. Constructs the owned object:
Overload Initializer for... Type of the owned object valueless_after_move()after construction
alloc the owned object
(1) (empty) (empty) T false
(2) a
(3) (empty) std::forward<U>(v) U
(4) a
(5) (empty) std::forward<Args>(args)
(6) a
(7) (empty) ilist, std::forward<Args>(args)
(8) a
(9) see below *other(only if other owns a value) the type of the object owned by other true only if other is valueless
(10) a
(11) std::move (other.alloc ) takes ownership(only if other owns a value)
(12) a see below
  1. _[alloc](../polymorphic.html#alloc "cpp/memory/polymorphic")_ is direct-non-list-initialized with std::allocator_traits<Allocator>::
    ``select_on_container_copy_construction(other._[alloc](../polymorphic.html#alloc "cpp/memory/polymorphic")_ ).

  2. The owned object is constructed as follows:

[edit] Constraints and supplement information

3,4) U

5,6) Args...

[edit] Exceptions

Throws nothing unless std::allocator_traits<Allocator>::allocate or std::allocator_traits<Allocator>::construct throws.

[edit] Example

[edit] See also