Namespaces
Variants

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

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until 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 持有值时)
true 仅当 other 为无值状态
( 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. alloc true ,则 * this 接管 other 的被管理对象所有权。
  • 否则,使用 alloc 通过 * std :: move ( other ) 构造被管理对象。

约束条件与补充信息

1,2) std:: is_default_constructible_v < T > false ,则程序非良构。

1) 此重载仅当 std:: is_default_constructible_v < Allocator > true 时参与重载决议。

3-8) 这些重载仅当 std:: is_constructible_v < T, /* argument types */ > true 时参与重载决议,其中 /* argument types */ 为:
3,4) U
5,6) Args...
7,8) std:: initializer_list < I > & , Args...

3,5,7) 这些重载仅当 std:: is_default_constructible_v < Allocator > true 时才参与重载决议。
3,4) 这些重载仅在以下所有值均为 false 时才参与重载决议:

9,10) std:: is_copy_constructible_v < T > false ,则程序非良构。
11,12) 构造完成后, other 将处于无值状态。
12) 如果 std:: allocator_traits < Allocator > :: is_always_equal :: value false T 不完整类型 ,则程序非良构。

异常

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

12)
noexcept 规范:
noexcept ( std:: allocator_traits < Allocator > :: is_always_equal :: value )

示例

参见

用于选择分配器感知构造函数重载的标签类型
(类)
原位构造标签
(标签)