std::allocator_traits::construct

定义于头文件 <memory>
template< class T, class... Args >
static void construct( Alloc& a, T* p, Args&&... args );
(C++11 起)

若可能,则在 p 所指向的分配的未初始化存储构造 T 类型对象,通过调用

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

若以上不可行(例如无 construct() 成员函数),则调用如下的布置 new

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

目录

参数

a - 用于构造的分配器
args... - 传递给 a.construct() 或布置 new 的参数

返回值

(无)

注意

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

因为此函数提供到布置 new 的自动回落,故 C++11 起成员函数 construct()分配器 (Allocator) 的可选要求。

参阅

分配函数
(函数)
(C++17 中弃用)
在分配的存储构造对象
(std::allocator 的公开成员函数)

版本历史

  • (当前 | 先前 2017年7月1日 (六) 23:06Fruderica讨论 | 贡献 . . (1,152字节) (-3). . (correction) (撤销)
  • 当前 | 先前 2017年6月4日 (日) 19:24Fruderica讨论 | 贡献. . (1,155字节) (-1,067). . (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:01P12bot讨论 | 贡献 . . (2,222字节) (-78). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 16:47P12bot讨论 | 贡献 . . (2,300字节) (+361). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 03:25P12讨论 | 贡献 . . (1,939字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (1,939字节) (-64). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:09P12讨论 | 贡献 . . (2,003字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (2,003字节) (+2,003). . (Translated from the English version using Google Translate)