By forwarded in-place construction, I take to mean std::allocator::construct and the various emplace methods, e.g., std::vector::emplace_back. I just find that forwarded in-place construction in C++ does not (unable to?) take advantage of the list-initialization syntax. As a result, it seems one can never forward in-place construct an aggregate. I just want to make sure whether forwarded in-place construction does not support list-initialization and hence aggregate types. Is this due to the limitation of the language? Could someone provide reference to the standard concerning this issue? Following is an illustration:
While we can do in-place construction directly like
int(*p)[3] = ...;
new(p) int[3]{1, 2, 3};
we cannot do forwarded in-place construction like
std::allocator<int[3]> allo;
allo.construct(p, 1, 2, 3);
Type object((foo, bar), anotherFoo, anotherBar);
? – Esthete{}
? – Furfurstd::allocator::construct
(andstd::allocator_traits::construct
) are specified to use()
rather than{}
, and must remain so for compatibility reasons (vector<int>(10, 10)
vs.vector<int>{10, 10}
). There's an LWG issue to make it fall back to using{}
if()
doesn't work. – Edwinedwina{}
may still surprise the programmers in some cases :) – Raskin