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) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

