Within our team's code review I found out a strange usage of struct initialization under C++17 and I'm surprised that it works:
struct TestStruct {
std::string test_str1;
std::string test_str2;
std::string test_str3;
};
TestStruct t{test_str1 : "col1", test_str3 : "col3"};
std::cout << "str1: " << t.test_str1 << "\nstr2:" << t.test_str2 << "\nstr3:" << t.test_str3;
and here's the result as follow:
str1: col1
str2:
str3: col3
I couldn't find references for such usage but it looks like Constructors and member initializer lists with some ellision.
Can someone explain why it works? Thanks :)