首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::scoped_allocator_adaptor::construct

Defined in header <scoped_allocator>

?

?

template < class T, class... Args > void construct( T* p, Args&&... args );

(1)

?

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)

?

template< class T1, class T2 > void construct( std::pair<T1, T2>* p );

(3)

?

template< class T1, class T2, class U, class V > void construct( std::pair<T1, T2>* p, U&& x, V&& y );

(4)

?

template< class T1, class T2, class U, class V > void construct( std::pair<T1, T2>* p, const std::pair<U, V>& xy );

(5)

?

template< class T1, class T2, class U, class V > void construct( std::pair<T1, T2>* p, std::pair<U, V>&& xy );

(6)

?

在已分配的但未初始化的存储中构造一个对象。p使用OuterAllocator和提供的构造函数参数。如果该对象的类型是它本身使用分配器,或者如果它是std::偶对,则将InnerAllocator向下传递给构造的对象。

首先,确定最外层的分配器类型。OUTERMOST它是通过调用this->outer_allocator(),然后调用outer_allocator()成员函数对此调用的结果进行递归处理,直到到达没有此类成员函数的类型为止。这种类型是最外层的分配器。

然后:

1%29std::uses_allocator<T, inner_allocator_type>::value==false28%T不使用分配器%29,如果std::is_constructible<T, Args...>::value==true然后打电话。

std::allocator_traits<OUTERMOST>::construct( OUTERMOST(*this),

p,

std::forward<Args>(args)... );

否则,如果std::uses_allocator<T, inner_allocator_type>::value==true28%T使用分配器,例如它是一个容器%29和如果std::is_constructible<T,std::allocator_arg_t, inner_allocator_type&, Args...>::value==true然后打电话。

std::allocator_traits<OUTERMOST>::construct( OUTERMOST(*this),

p,

std::allocator_arg,

inner_allocator(),

std::forward<Args>(args)... );

否则,std::uses_allocator<T, inner_allocator_type>::value==true28%T使用分配器,例如它是一个容器%29和如果std::is_constructible<T, Args..., inner_allocator_type&>::value==true然后打电话。

std::allocator_traits<OUTERMOST>::construct( OUTERMOST(*this),

p,

std::forward<Args>(args)...,

inner_allocator());

否则,将发出编译错误,因为尽管std::uses_allocator<T>声称T是分配器感知的,它缺少任何一种形式的分配器接受构造函数.

2%29T1T2是分配器感知的,可以修改元组。xy包含适当的内部分配器,从而生成两个新的元组。xprimeyprime根据以下三条规则:

2A%29T1不知道分配器的百分比28std::uses_allocator<T1, inner_allocator_type>::value==false,然后xprimex,未经修饰。%28还要求std::is_constructible<T1, Args1...>::value==true29%。

2B%29T1是否分配器感知%28std::uses_allocator<T1, inner_allocator_type>::value==true%29,其构造函数接受分配器标记%28std::is_constructible<T1,std::allocator_arg_t, inner_allocator_type&, Args1...>::value==true,然后xprimestd::tuple_cat(std::tuple<std::allocator_arg_t, inner_allocator_type&>(std::allocator_arg,

inner_allocator()

), std::move(x))...

2C%29T1是否分配器感知%28std::uses_allocator<T1, inner_allocator_type>::value==true%29,其构造函数将分配程序作为最后一个参数%28。std::is_constructible<T1, Args1..., inner_allocator_type&>::value==true%29,那么xprimestd::tuple_cat(std::move(x),std::tuple<inner_allocator_type&>(inner_allocator()))...

同样的规则适用于T2和替换y带着yprime...

一次xprimeyprime这还要求Args 1...和Args 2...中的所有类型都是CopyConstructible%29,构造成对p在分配的存储中调用。

std::allocator_traits<OUTERMOST>::construct( OUTERMOST(*this),

p,

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::vector,那是一个std::scoped_allocator_adaptor作为分配程序使用。自inner_allocator本身是std::scoped_allocator_adaptor,当通过此函数构造的感知分配程序的对象开始构建自己的成员时,也会调用此函数。

另见

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)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com