In the following code, I am trying to use aggregate initialization with emplace_back. The catch here is that emplace_back takes the constructor arguments and constructs the object directly in the vector, and I want to know whether the copy constructor is called on a A{1,2,3}
or not. However, for aggregate initialization to work, the struct should not have a user-defined constructor. Any ideas what's happening behind the scenes?
#include <iostream>
#include <vector>
struct A {
int x, y, z;
/*A(int x, int y, int z) : x(x), y(y), z(z)
{
std::cout << "ctor called\n";
}
A(const A& other) : x(other.x), y(other.y), z(other.z) {
std::cout << "copy ctor called\n";
}*/
};
int main() {
std::vector<A> vec;
vec.emplace_back(A{1, 2, 3});
return 0;
}