std::vector::emplace_back()
is used to construct the new element directly at the end of the vector. This is allocated through std::allocator_traits::construct
which uses parens and not braces to initialize. This means it does not do uniform or aggregate initialization.
From C++20, parentheses are allowed for aggregate initialization. So emplace_back
can do aggregate initialization as well.
struct A{
int a;
};
int main() {
std::vector<A> vec;
vec.emplace_back(1);
}
The above code doesn’t compile for C++17, but compiles for C++20.
Read More: