Does anyone would like to explain why case 1 and case 2 have different output for this code snippet.
struct A {
A() { cout << "A()" << endl; }
A(int i) { cout << "A(int)" << endl; }
A(const A&) { cout << "A(const A&)" << endl; }
A(A&&) noexcept { cout << "A(A&&)" << endl; }
A& operator=(const A&) { cout << "operator=(const A&)" << endl; return *this; }
A& operator=(A&&) noexcept { cout << "operator=(A&&)" << endl; return *this; }
friend bool operator< (const A&, const A&) { return true; }
};
int main() {
std::set<A> aSet;
aSet.insert(1); // case 1
//aSet.insert({1}); // case 2
return 0;
}
For case 1, the output is:
A(int)
A(A&&)
and for case 2 is:
A(int)
A(const A&)
The compiler version is:
g++ --version g++-7 (SUSE Linux) 7.2.1 20170901 [gcc-7-branch revision 251580] Copyright (C) 2017 Free Software Foundation, Inc.