std::polymorphic<T, Allocator>:: polymorphic
|
constexpr
explicit
polymorphic
(
)
;
|
(1) | (自 C++26 起) |
|
constexpr
explicit
polymorphic
(
std::
allocator_arg_t
,
const
Allocator
&
a
)
;
|
(2) | (自 C++26 起) |
|
template
<
class
U
=
T
>
constexpr explicit polymorphic ( U && v ) ; |
(3) | (自 C++26 起) |
|
template
<
class
U
=
T
>
constexpr
explicit
polymorphic
(
std::
allocator_arg_t
,
const
Allocator
&
a,
|
(4) | (自 C++26 起) |
|
template
<
class
U,
class
...
Args
>
constexpr explicit polymorphic ( std:: in_place_type_t < U > , Args && ... args ) ; |
(5) | (自 C++26 起) |
|
template
<
class
U,
class
...
Args
>
constexpr
explicit
polymorphic
(
std::
allocator_arg_t
,
const
Allocator
&
a,
|
(6) | (自 C++26 起) |
|
template
<
class
U,
class
I,
class
...
Args
>
constexpr
explicit
polymorphic
(
std::
in_place_type_t
<
U
>
,
|
(7) | (自 C++26 起) |
|
template
<
class
U,
class
I,
class
...
Args
>
constexpr
explicit
polymorphic
(
std::
allocator_arg_t
,
const
Allocator
&
a,
|
(8) | (自 C++26 起) |
|
constexpr
polymorphic
(
const
polymorphic
&
other
)
;
|
(9) | (自 C++26 起) |
|
constexpr
polymorphic
(
std::
allocator_arg_t
,
const
Allocator
&
a,
const polymorphic & other ) ; |
(10) | (自 C++26 起) |
|
constexpr
polymorphic
(
polymorphic
&&
other
)
noexcept
;
|
(11) | (自 C++26 起) |
|
constexpr
polymorphic
(
std::
allocator_arg_t
,
const
Allocator
&
a,
polymorphic && other ) noexcept ( /* 见下文 */ ) ; |
(12) | (自 C++26 起) |
构造一个新的
polymorphic
对象。
目录 |
参数
| a | - | 要关联的分配器 |
| v | - | 用于初始化所拥有值的初始值 |
| args | - | 用于初始化所拥有值的参数 |
| il | - | 用于初始化所拥有值的初始化列表 |
| other | - |
另一个
polymorphic
对象,其拥有的值(若存在)将被复制
|
效果
新
polymorphic
对象的构建包含以下步骤:
-
对于重载
(
1-8
)
,调用
std::
allocator_traits
<
Allocator
>
::
construct
(
alloc ,p, args... ) ,其中-
p
是类型为
U*的指针,指向适合构造被管理对象的存储空间,且 - args... 是包含初始化参数的表达式包。
-
p
是类型为
- 对于重载 ( 9-12 ) :
| 重载版本 | 初始化器用于... | 所拥有对象的类型 |
valueless_after_move()
构造后状态 |
|
|---|---|---|---|---|
alloc
|
所拥有对象 | |||
| ( 1 ) | (空) | (空) |
T
|
false |
| ( 2 ) | a | |||
| ( 3 ) | (空) | std:: forward < U > ( v ) |
U
|
|
| ( 4 ) | a | |||
| ( 5 ) | (空) | std:: forward < Args > ( args ) | ||
| ( 6 ) | a | |||
| ( 7 ) | (空) |
ilist,
std:: forward < Args > ( args ) |
||
| ( 8 ) | a | |||
| ( 9 ) | 见下文 |
*
other
(仅当 other 拥有值时) |
other 所拥有对象的类型 | true 仅当 other 为无值状态 |
| ( 10 ) | a | |||
| ( 11 ) |
std
::
move
(
other.
alloc
)
|
取得所有权
(仅当 other 拥有值时) |
||
| ( 12 ) | a | 见下文 | ||
alloc
通过
std::
allocator_traits
<
Allocator
>
::
select_on_container_copy_construction
(
other.
alloc
)
进行直接非列表初始化。
约束条件与补充信息
- std:: derived_from < std:: remove_cvref_t < U > , T >
- std:: is_copy_constructible_v < std:: remove_cvref_t < U >>
- std:: is_constructible_v < std:: remove_cvref_t < U > , /* argument types */ > ,其中 /* argument types */ 为:
U
Args...
- std:: is_same_v < std:: remove_cvref_t < U > , std :: polymorphic > 为 false 。
-
U不是 std::in_place_type_t 的特化。
异常
除非 std:: allocator_traits < Allocator > :: allocate 或 std:: allocator_traits < Allocator > :: construct 抛出异常,否则不会抛出任何异常。
示例
|
本节内容不完整
原因:缺少示例 |
另请参阅
|
(C++11)
|
用于选择分配器感知构造函数重载的标签类型
(类) |
|
原位构造标签
(标签) |