std::indirect<T, Allocator>::indirect
来自cppreference.com
constexpr explicit indirect(); | (1) | (C++26 起) |
constexpr explicit indirect( std::allocator_arg_t, const Allocator& a ); | (2) | (C++26 起) |
template< class U = T > constexpr explicit indirect( U&& v ); | (3) | (C++26 起) |
template< class U = T > constexpr explicit indirect( std::allocator_arg_t, const Allocator& a, | (4) | (C++26 起) |
template< class... Args > constexpr explicit indirect( std::in_place_t, Args&&... args ); | (5) | (C++26 起) |
template< class... Args > constexpr explicit indirect( std::allocator_arg_t, const Allocator& a, | (6) | (C++26 起) |
template< class I, class... Args > constexpr explicit indirect( std::in_place_t, std::initializer_list<I> ilist, | (7) | (C++26 起) |
template< class I, class... Args > constexpr explicit indirect( std::allocator_arg_t, const Allocator& a, | (8) | (C++26 起) |
constexpr indirect( const indirect& other ); | (9) | (C++26 起) |
constexpr indirect( std::allocator_arg_t, const Allocator& a, const indirect& other ); | (10) | (C++26 起) |
constexpr indirect( indirect&& other ) noexcept; | (11) | (C++26 起) |
constexpr indirect( std::allocator_arg_t, const Allocator& a, indirect&& other ) noexcept(/* 见下文 */); | (12) | (C++26 起) |
构造新的 indirect
对象。
参数
a | - | 要关联的分配器 |
v | - | 用来初始化拥有的值的值 |
args | - | 用来初始化拥有的值的实参 |
il | - | 用来初始化拥有的值的初始化器列表 |
other | - | 另一个 indirect 对象,它包含的值(如果存在)会被复制 |
效果
新 indirect
对象的构造包含以下步骤:
2) 构造拥有的对象:
- 对于重载 (1-8),首先以调用 std::allocator_traits<Allocator>::allocate 的结果来初始化
p
,然后调用 std::allocator_traits<Allocator>::construct(alloc
,p
, args...),其中 args... 是包含各初始化器实参的表达式包。 - 对于重载 (9-12):
重载 | ...的初始化器 | 构造后的 valueless_after_move() | |
---|---|---|---|
alloc | 拥有的对象 | ||
(1) | (空) | (空) | false |
(2) | a | ||
(3) | (空) | std::forward<U>(v) | |
(4) | a | ||
(5) | (空) | std::forward<Args>(args) | |
(6) | a | ||
(7) | (空) | ilist, std::forward<Args>(args) | |
(8) | a | ||
(9) | 见下文 | *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) 拥有的对象会按以下方式初始化:
约束和补充信息
如果 std::is_default_constructible_v<T> 是 false,那么程序非良构。
3) 此重载只有在满足以下所有条件时才会参与重载决议:
- std::is_same_v<std::remove_cvref_t<U>, std::indirect> 是 false。
- std::is_same_v<std::remove_cvref_t<U>, std::in_place_t> 是 false。
- std::is_constructible_v<T, U> 是 true。
- std::is_default_constructible_v<Allocator> 是 true。
4) 此重载只有在满足以下所有条件时才会参与重载决议:
- std::is_same_v<std::remove_cvref_t<U>, std::indirect> 是 false。
- std::is_same_v<std::remove_cvref_t<U>, std::in_place_t> 是 false。
- std::is_constructible_v<T, U> 是 true。
5) 此重载只有在以下所有值都是 true 时才会参与重载决议:
- std::is_constructible_v<T, Args...>
- std::is_default_constructible_v<Allocator>
7) 此重载只有在以下所有值都是 true 时才会参与重载决议:
- std::is_constructible_v<T, std::initializer_list<I>&, Args...>
- std::is_default_constructible_v<Allocator>
11) 当构造完成时,other 无值。
异常
除非 std::allocator_traits<Allocator>::allocate 或 std::allocator_traits<Allocator>::construct 抛出异常,否则不会抛出异常。
12)
noexcept 说明:
noexcept(std::allocator_traits<Allocator>::is_always_equal::value)
示例
本节未完成 原因:暂无示例 |
参阅
(C++11) | 标签类型,用于选择具分配器的构造函数重载 (类) |
原位构造标签 (类模板) |