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)
(Anmerkung: Der bereitgestellte HTML-Code enthält keinen übersetzbaren Text, da alle Tags und Attribute gemäß den Anweisungen unverändert bleiben sollen und die Tabellenzellen leer sind.)
constexpr explicit polymorphic ( ) ;
(1) (seit C++26)
constexpr explicit polymorphic ( std:: allocator_arg_t , const Allocator & a ) ;
(2) (seit C++26)
template < class U = T >
constexpr explicit polymorphic ( U && v ) ;
(3) (seit C++26)
template < class U = T >

constexpr explicit polymorphic ( std:: allocator_arg_t , const Allocator & a,

U && v ) ;
(4) (seit C++26)
template < class U, class ... Args >
constexpr explicit polymorphic ( std:: in_place_type_t < U > , Args && ... args ) ;
(5) (seit 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) (seit 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) (seit 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) (seit C++26)
constexpr polymorphic ( const polymorphic & other ) ;
(9) (seit C++26)
constexpr polymorphic ( std:: allocator_arg_t , const Allocator & a,
const polymorphic & other ) ;
(10) (seit C++26)
constexpr polymorphic ( polymorphic && other ) noexcept ;
(11) (seit C++26)
constexpr polymorphic ( std:: allocator_arg_t , const Allocator & a,
polymorphic && other ) noexcept ( /* siehe unten */ ) ;
(12) (seit C++26)

Konstruiert ein neues polymorphic Objekt.

Inhaltsverzeichnis

Parameter

a - der zuzuordnende Allokator
v - Wert zur Initialisierung des enthaltenen Werts
args - Argumente zur Initialisierung des enthaltenen Werts
il - Initialisierungsliste zur Initialisierung des enthaltenen Werts
other - ein weiteres polymorphic Objekt, dessen enthaltener Wert (falls vorhanden) kopiert wird

Auswirkungen

Die Erstellung eines neuen polymorphic Objekts besteht aus den folgenden Schritten:

1) Konstruiert den zugehörigen Allokator alloc :
2) Konstruiert das verwaltete Objekt:
  • Für Überladungen ( 1-8 ) , ruft std:: allocator_traits < Allocator > :: construct ( alloc  , p, args... ) , wobei
    • p ein Zeiger vom Typ U* ist, der auf Speicherplatz für das zu konstruierende verwaltete Objekt zeigt, und
    • args... ein Ausdruckspaket mit den Initialisierungsargumenten ist.
  • Für Überladungen ( 9-12 ) :
    • Wenn other wertlos ist, wird kein verwaltetes Objekt konstruiert, und * this ist nach der Konstruktion ebenfalls wertlos.
    • Andernfalls, wenn other eine Rvalue-Referenz ist und alloc gleich other. alloc ist, * this übernimmt das Eigentum am verwalteten Objekt von other .
    • Andernfalls wird das verwaltete Objekt unter Verwendung von alloc wie oben beschrieben konstruiert, wobei der Typ von p durch den Typ des von other verwalteten Objekts bestimmt wird.
Überladung Initialisierer für... Typ des besessenen Objekts valueless_after_move()
nach Konstruktion
alloc das besessene Objekt
( 1 ) (leer) (leer) T false
( 2 ) a
( 3 ) (leer) std:: forward < U > ( v ) U
( 4 ) a
( 5 ) (leer) std:: forward < Args > ( args )
( 6 ) a
( 7 ) (leer) ilist,
std:: forward < Args > ( args )
( 8 ) a
( 9 ) siehe unten * other
(nur wenn other einen Wert besitzt)
der Typ des von other besessenen Objekts true nur wenn other wertlos ist
( 10 ) a
( 11 ) std :: move 
( other. alloc  )
übernimmt Besitz
(nur wenn other einen Wert besitzt)
( 12 ) a siehe unten
9) alloc wird direkt-nicht-Listen-initialisiert mit std:: allocator_traits < Allocator > ::
select_on_container_copy_construction ( other. alloc  )
.
12) Das besessene Objekt wird wie folgt konstruiert:
  • Wenn other wertlos ist, * this ist ebenfalls wertlos.
  • Andernfalls, wenn alloc == other. alloc true ist, * this übernimmt den Besitz des besessenen Objekts von other .
  • Andernfalls wird ein besessenes Objekt mit * std :: move ( other ) unter Verwendung von alloc konstruiert.

Einschränkungen und ergänzende Informationen

1,2) Wenn einer der folgenden Werte false ist, ist das Programm fehlerhaft:

1) Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn std:: is_default_constructible_v < Allocator > true ist.

3-8) Diese Überladungen nehmen nur dann an der Überladungsauflösung teil, wenn die folgenden Werte alle true sind:
3,4) U
5,6) Args...
7,8) std:: initializer_list < I > & , Args...

3,5,7) Diese Überladungen nehmen nur dann an der Überladungsauflösung teil, wenn std:: is_default_constructible_v < Allocator > true ist.
3,4) Diese Überladungen nehmen an der Überladungsauflösung nur teil, wenn alle folgenden Bedingungen erfüllt sind:
5-8) Diese Überladungen nehmen an der Überladungsauflösung nur teil, wenn std:: is_same_v < std:: remove_cvref_t < U > , U > true ist.

Exceptions

Wirft nichts, es sei denn std:: allocator_traits < Allocator > :: allocate oder std:: allocator_traits < Allocator > :: construct werfen.

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

Beispiel

Siehe auch

Markierungstyp zur Auswahl von Allokator-konstruktorüberladungen
(Klasse)
In-place-Konstruktionsmarkierung
(Markierung)