std::polymorphic<T, Allocator>::polymorphic
来自cppreference.com
< cpp | memory | 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(/* see below */); |
(12) | (C++26 起) |
构造新的 polymorphic 对象。
参数
| a | - | 要关联的分配器 |
| v | - | 用来初始化拥有的值的值 |
| args | - | 用来初始化拥有的值的实参 |
| il | - | 用来初始化拥有的值的初始化器列表 |
| other | - | 另一个 polymorphic 对象,它包含的值(如果存在)会被复制
|
效果
新 polymorphic 对象的构造包含以下步骤:
2) 构造拥有的对象:
| 重载 | ...的初始化器 | 拥有的对象的类型 | 构造后的 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 拥有的对象的类型
|
仅当 other 无值时是 true |
| (10) | a | |||
| (11) | std::move (other.alloc )
|
获得所有权 (仅当 other 有值) | ||
| (12) | a | 见下文 | ||
9)
alloc 会以 std::allocator_traits<Allocator>:: select_on_container_copy_construction(other.alloc ) 直接非列表初始化。12) 拥有的对象会按以下方式初始化:
约束和补充信息
3-8) 这些重载只有在以下所有值都是 true 时才会参与重载决议:
- 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>, /* 实参类型 */>,其中 /* 实参类型 */ 是:
3,4)
U5,6)
Args...7,8) std::initializer_list<I>&, Args...
3,4) 这些重载只有在满足以下所有条件时才会参与重载决议:
- 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 抛出异常,否则不会抛出异常。
12)
noexcept 说明:
noexcept(std::allocator_traits<Allocator>::is_always_equal::value)
示例
| 本节未完成 原因:暂无示例 |
参阅
| (C++11) |
标签类型,用于选择具分配器的构造函数重载 (类) |
| 原位构造标签 (类模板) |