Namespaces
Variants

std::polymorphic<T, Allocator>:: polymorphic

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
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

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

Effects

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

1) Constructs the associated allocator alloc :
2) Constructs the owned object:
  • For overloads ( 1-8 ) , calls std:: allocator_traits < Allocator > :: construct ( alloc  , p, args... ) , where
    • p is a pointer of type U* , it points to storage suitable for the owned object to be constructed, and
    • args... is an expression pack containing the initializer arguments.
  • For overloads ( 9-12 ) :
    • If other is valueless, no owned object is constructed, and * this is also valueless after construction.
    • Otherwise, if other is an rvalue reference and alloc equals other. alloc , * this takes ownership of the owned object of other .
    • Otherwise, the owned object is constructed using alloc as described above, where the type of p is determined by the type of the object owned by other .
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
9) alloc is direct-non-list-initialized with std:: allocator_traits < Allocator > ::
select_on_container_copy_construction ( other. alloc  )
.
12) The owned object is constructed as follows:
  • If other is valueless, * this is also valueless.
  • Otherwise, if alloc == other. alloc is true , * this takes ownership of the owned object of other .
  • Otherwise, constructs an owned object with * std :: move ( other ) using alloc .

Constraints and supplement information

1,2) If any of the following values is false , the program is ill-formed:

1) This overload participates in overload resolution only if std:: is_default_constructible_v < Allocator > is true .

3-8) These overloads participate in overload resolution only if the following values are all true :
3,4) U
5,6) Args...
7,8) std:: initializer_list < I > & , Args...

3,5,7) These overloads participate in overload resolution only if std:: is_default_constructible_v < Allocator > is true .
3,4) These overloads participate in overload resolution only if all following conditions are satisfied:
5-8) These overloads participate in overload resolution only if std:: is_same_v < std:: remove_cvref_t < U > , U > is true .

Exceptions

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

12)
noexcept specification:
noexcept ( std:: allocator_traits < Allocator > :: is_always_equal :: value )

Example

See also

tag type used to select allocator-aware constructor overloads
(class)
in-place construction tag
(tag)