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

std::allocator_traits::construct

Defined in header <memory>

?

?

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

?

(since C++11)

如果可能,构造一个类型为T在分配的未初始化存储中,p打电话。

a.construct(p,std::forward<Args>(args)...)...

如果以上不可能,则为%28例如。a没有成员函数construct(),%29,然后调用布局-新AS。

::new(static_cast<void*>(p)) T(std::forward<Args>(args)...)...

参数

a

-

allocator to use for construction

args...

-

the constructor arguments to pass to a.construct() or to placement-new

返回值

%280%29

注记

标准库容器在插入、复制或移动元素时使用此函数。

因为这个函数提供了自动返回布局的新功能,所以成员函数construct()是可选的Allocator要求自C++11。

另见

operator newoperator new[]

allocation functions (function)

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