Ternary operator + C++11 constructor from initializer_list
问题 While developing an application, I had the following problem. I wanted to return an empty std::list<string> when a given function pointer was null, or the result of that function otherwise. This is a simplified version of my code: typedef std::list<std::string> (*ParamGenerator)(); std::list<std::string> foo() { /* ... */ ParamGenerator generator = ...; if(generator) return generator(); else return {}; } However, I usually like to use the ternary ( ?: ) operator in these cases, so I tried