Specifies that an object of the type can be constructed into uninitialized storage from an rvalue of that type by a given allocator.
[edit]Requirements
Given the following types, values and expressions:
| Type | Definition |
T | an object type |
A | an allocator type |
X | a container type satisfying all following conditions: |
| Value | Definition |
| m | an lvalue of typeA |
| p | a pointer of typeT* |
| Expression | Definition |
| rv | an expression denoting an rvalue of typeT |
| expr | std::allocator_traits<A>::construct(m, p, rv) |
T isMoveInsertable intoX if all following conditions are satisfied:
- expr is well-formed.
- Right after the evaluation ofexpr, the value of*p is equivalent to the value ofrv before the evaluation.
IfA isstd::allocator<T>, then this will call placementnew, as by::new((void*)p) T(rv)(until C++20)std::construct_at(p, rv)(since C++20). This effectively requiresT to be move constructible.
Ifstd::allocator<T> or a similar allocator is used, a class does not have to implement amove constructor to satisfy this type requirement: acopy constructor that takes aconst T& argument can bind rvalue expressions. If aMoveInsertable class implements a move constructor, it may also implementmove semantics to take advantage of the fact that the value ofrv after construction is unspecified.
Although it is required that customizedconstruct is used when constructing elements ofstd::basic_string until C++23, all implementations only used the default mechanism. The requirement is corrected byP1072R10 to match existing practice.
[edit]Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|
| LWG 2177 | C++11 | evalutingexpr did not have any postcondition | added |
[edit]See also