std:: polymorphic
|
Defined in header
<memory>
|
||
|
template
<
class
T,
class
Allocator
=
std::
allocator
<
T
>
>
class polymorphic ; |
(1) | (since C++26) |
|
namespace
pmr
{
template
<
class
T
>
|
(2) | (since C++26) |
std::polymorphic
is a wrapper containing dynamically-allocated object of possibly different types with value-like semantics.
An
std::polymorphic
object manages the
lifetime
of an owned object. The owned object is of type
T
or any type (publicly and unambiguously) derived from
T
. An
std::polymorphic
object can only have no owned object after it has been moved from, in this case it is
valueless
.
Every object of type
std::polymorphic<T, Allocator>
uses an object of type
Allocator
to allocate and free storage for the owned object as needed.
If a program declares an explicit or partial specialization of
std::polymorphic
, the behavior is undefined.
Contents |
Template parameters
| T | - | the type of the owned object |
| Allocator | - | the type of the associated allocator |
| Type requirements | ||
-
T
may be an
incomplete type
.
|
||
-
T
is one of the following types, the program is ill-formed:
|
||
-
Allocator
does not satisfy the requirements of
Allocator
, the program is ill-formed.
|
||
-
T
, the program is ill-formed.
|
||
Nested types
| Type | Definition |
value_type
|
T
|
allocator_type
|
Allocator
|
pointer
|
typename std:: allocator_traits < Allocator > :: pointer |
const_pointer
|
typename std:: allocator_traits < Allocator > :: const_pointer |
Data members
| Member | Description |
Allocator
alloc
|
the asociated allocator
( exposition-only member object* ) |
Member functions
constructs the
polymorphic
object
(public member function) |
|
|
destroys the owned value, if there is one
(public member function) |
|
|
assigns contents
(public member function) |
|
Observers |
|
|
accesses the owned value
(public member function) |
|
checks if the
polymorphic
is valueless
(public member function) |
|
|
returns the associated allocator
(public member function) |
|
Modifiers |
|
|
exchanges the contents
(public member function) |
|
Non-member functions
|
(C++26)
|
specializes the
std::swap
algorithm
(function template) |
Notes
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_polymorphic
|
202502L
|
(C++26) |
std::polymorphic
|
Example
|
This section is incomplete
Reason: no example |
See also
|
(C++26)
|
a wrapper containing dynamically-allocated object with value-like semantics
(class template) |