std::allocator::construct(3)
π std::allocator::construct(3) π
okay so bestie, welcome to the std::allocator::construct(3) page from the C++ Standard Library manual. this one is a little vintage, a little deprecated, and honestly kind of iconic in a βwe used to do it this wayβ way. letβs get into it π
β¨ NAME β¨
std::allocator::construct β std::allocator::construct (yes, the name is literally the name, periodt π
π Synopsis π
Defined in header <memory> β noted, bestie π
void construct( pointer p, const_reference val ); (1) (until C++11)
template< class U, class... Args > (since C++11)
void construct( U* p, Args&&... args ); (2) (deprecated in C++17)
(removed in C++20)
okay so what does it do? it constructs an object of type T in allocated uninitialized storage pointed to by p, using global placement-new. the way that this is literally placement-new with extra steps is sending me π
- Calls
::new((void*)p) T(val). - Calls
::new((void*)p) U(std::forward<Args>(args)...).
β οΈ heads up: overload (2) is deprecated in C++17 and removed in C++20 β not me being dramatic, thatβs just the timeline π
πΈ Parameters πΈ
pβ pointer to allocated uninitialized storagevalβ the value to use as the copy constructor argumentargs...β the constructor arguments to use
thatβs the whole squad, no cap π«Ά
π Return value π
(none) β literally nothing comes back, bestie. itβs giving void energy π«Ά
π«Ά Defect reports π«Ά
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- LWG 402 β Applied to: C++98. Behavior as published: if
T::operator newexists, the program might be ill-formed. Correct behavior: uses global replacement-new instead. π§
π₯ See also π₯
construct[static] β constructs an object in the allocated storage (function template)construct_at(C++20) β creates an object at a given address (function template)operator newβ allocation functionsoperator new[]β (function)
mwah π β source: http://cppreference.com β version/date: 2024.06.10 β std::allocator::construct(3) π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms