std::indirect<T, Allocator>::indirect

来自cppreference.com
< cpp‎ | memory‎ | indirect
 
 
内存管理库
(仅用于阐述*)
分配器
未初始化内存算法
受约束的未初始化内存算法
内存资源
未初始化存储 (C++20 前)
(C++17 弃用)
(C++17 弃用)
垃圾收集器支持 (C++23 前)
(C++11)(C++23 前)
(C++11)(C++23 前)
(C++11)(C++23 前)
(C++11)(C++23 前)
(C++11)(C++23 前)
(C++11)(C++23 前)
 
 
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,

                             U&& v );
(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,

                             std::in_place_t, Args&&... args );
(6)(C++26 起)
template< class I, class... Args >

constexpr explicit indirect( std::in_place_t, std::initializer_list<I> ilist,

                             Args&&... args );
(7)(C++26 起)
template< class I, class... Args >

constexpr explicit indirect( std::allocator_arg_t, const Allocator& a,
                             std::in_place_t, std::initializer_list<I> ilist,

                             Args&&... args );
(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 对象的构造包含以下步骤:

1) 构造关联的分配器 alloc
2) 构造拥有的对象:
  • 对于重载 (1-8),首先以调用 std::allocator_traits<Allocator>::allocate 的结果来初始化 p,然后调用 std::allocator_traits<Allocator>::construct(alloc , p , args...),其中 args... 是包含各初始化器实参的表达式包。
  • 对于重载 (9-12)
    • 如果 other 无值,那么不会构造拥有的对象,并且 *this 在构造后同样无值。
    • 否则,如果 other 是右值引用,并且 alloc 等于 other.alloc,那么 *this 会获得 other 拥有的对象的所有权。
    • 否则会按上述方法通过 alloc 构造拥有的对象。
  重载  ...的初始化器 构造后的 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) 拥有的对象会按以下方式初始化:
  • 如果 other 无值,那么 *this 同样无值。
  • 否则,如果 alloc == other.alloctrue,那么 *this 会获取 other 拥有的对象的所有权。
  • 否则通过 alloc*std::move(other) 构造拥有的对象。

约束和补充信息

1) 此重载只有在 std::is_default_constructible_v<Allocator>true时才会参与重载决议。
如果 std::is_default_constructible_v<T>false,那么程序非良构。
2) 如果 std::is_default_constructible_v<T>false,那么程序非良构。
3) 此重载只有在满足以下所有条件时才会参与重载决议:
4) 此重载只有在满足以下所有条件时才会参与重载决议:
5) 此重载只有在以下所有值都是 true 时才会参与重载决议:
6) 此重载只有在 std::is_constructible_v<T, Args...>true 时才会参与重载决议。
7) 此重载只有在以下所有值都是 true 时才会参与重载决议:
8) 此重载只有在 std::is_constructible_v<T, std::initializer_list<I>&, Args...>true 时才会参与重载决议。
9,10) 如果 std::is_copy_constructible_v<T>false ,那么程序非良构。
11) 当构造完成时,other 无值。
12) 如果 std::allocator_traits<Allocator>::is_always_equal::valuefalseT不完整类型,那么程序非良构。

异常

除非 std::allocator_traits<Allocator>::allocatestd::allocator_traits<Allocator>::construct 抛出异常,否则不会抛出异常。

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

示例

参阅

标签类型,用于选择具分配器的构造函数重载
(类)
原位构造标签
(类模板)