initializer_list copy count
How many times is the copy constructor of C called by this program?
#include <initializer_list>
#include <iostream>
class C {
public:
C() = default;
C(const C&) { std::cout << 1; }
};
void f(std::initializer_list<C> i) {}
int main() {
C c;
std::initializer_list<C> i{c};
f(i);
f(i);
}
Sign in to answer questions and track your progress
Sign In