std::pmr::polymorphic_allocator::construct
template < class U, class... Args > void construct( U* p, Args&&... args ); | (1) | (since C++17) |
---|---|---|
template< class T1, class T2, class... Args1, class... Args2 > void construct( std::pair<T1, T2>* p, std::piecewise_construct_t, std::tuple<Args1...> x, std::tuple<Args2...> y ); | (2) | (since C++17) |
template< class T1, class T2 > void construct( std::pair<T1, T2>* p ); | (3) | (since C++17) |
template< class T1, class T2, class U, class V > void construct( std::pair<T1, T2>* p, U&& x, V&& y ); | (4) | (since C++17) |
template< class T1, class T2, class U, class V > void construct( std::pair<T1, T2>* p, const std::pair<U, V>& xy ); | (5) | (since C++17) |
template< class T1, class T2, class U, class V > void construct( std::pair<T1, T2>* p, std::pair<U, V>&& xy ); | (6) | (since C++17) |
pthis->resource()
1%29std::uses_allocator<U, memory_resource*>::value==false
28%Ustd::is_constructible<U, Args...>::value==true
,然后将对象构造为::new((void*) p) U(std::forward<Args>(args)... );
...
否则,如果std::uses_allocator<U, memory_resource*>::value==true
28%U
使用分配器,例如它是一个容器%29和std::is_constructible<U,std::allocator_arg_t, memory_resource*, Args...>::value==true
,然后将对象构造为::new((void*) p) U(std::allocator_arg, this->resource(),std::forward<Args>(args)... );
...
否则,如果std::uses_allocator<U, memory_resource*>::value==true
28%U
使用分配器,例如它是一个容器%29和std::is_constructible<U, Args..., memory_resource*>::value==true
,然后将对象构造为::new((void*) p) U(std::forward<Args>(args)..., this->resource());
...
否则,这个程序就会有错误的形式。
T1
或T2
是分配器感知的,可以修改元组。x
和y
包括this->resource()
,产生了两个新的元组。xprime
和yprime
根据以下三条规则:
2A%29T1
不知道分配器的百分比28std::uses_allocator<T1, memory_resource*>::value==false
29%和std::is_constructible<T1, Args1...>::value==true
,然后xprime
是x
,未经修饰。
2B%29T1
是否分配器感知%28std::uses_allocator<T1, memory_resource*>::value==true
%29,其构造函数接受分配器标记%28std::is_constructible<T1,std::allocator_arg_t, memory_resource*, Args1...>::value==true
,然后xprime
是std::tuple_cat(std::make_tuple(std::allocator_arg, this->resource()), std::move(x))
...
2C%29T1
是否分配器感知%28std::uses_allocator<T1, memory_resource*>::value==true
%29,其构造函数将分配程序作为最后一个参数%28。std::is_constructible<T1, Args1..., memory_resource*>::value==true
%29,那么xprime
是std::tuple_cat(std::move(x),std::make_tuple(this->resource()))
...
2D%29,否则,程序是错误的.
同样的规则适用于T2
和替换y
带着yprime
...
一次xprime
和yprime
构造,构造成对p
在分配的存储中,就好像::new((void*) p) pair<T1, T2>(std::piecewise_construct, std::move(xprime), std::move(yprime));
3%29相当于construct(p,std::piecewise_construct,std::tuple<>(),std::tuple<>())
也就是说,如果接受的话,将内存资源传递给对%27s成员类型。
4%29相当于。
construct(p,std::piecewise_construct,std::forward_as_tuple(std::forward<U>(x)),
std::forward_as_tuple(std::forward<V>(y)))
...
5%29相当于。
construct(p,std::piecewise_construct,std::forward_as_tuple(xy.first),
std::forward_as_tuple(xy.second))
...
6%29相当于。
construct(p,std::piecewise_construct,std::forward_as_tuple(std::forward<U>(xy.first)),
std::forward_as_tuple(std::forward<V>(xy.second)))
...
参数
p | - | pointer to allocated, but not initialized storage |
---|---|---|
args... | - | the constructor arguments to pass to the constructor of T |
x | - | the constructor arguments to pass to the constructor of T1 |
y | - | the constructor arguments to pass to the constructor of T2 |
xy | - | the pair whose two members are the constructor arguments for T1 and T2 |
返回值
%280%29
注记
这个函数被称为%28std::allocator_traits
%29由任何分配器感知对象执行,如std::pmr::vector
%28或其他std::vector
给了我一个std::std::polymorphic_allocator
作为分配程序使用%29。自memory_resource*
隐式转换为polymorphic_allocator
,内存资源指针将使用多态分配器传播到任何感知分配器的子对象。
另见
construct static | constructs an object in the allocated storage (function template) |
---|---|
construct (deprecated in C++17) | constructs an object in allocated storage (public member function of std::allocator) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com