4 ms·
Is return /* ... */ throw invalid_argument(""); really valid C++11?
by hythloday 15y ago
Is
return /* ... */ throw invalid_argument("");
really valid C++11?
- alexk7 15y ago"The rules for conditional operator are quite sophisticated and one of them says that if one of the sub-expressions is a throw expression, the type of the entire conditional operator is that of the other sub-expression." [1] [1] http://akrzemi1.wordpress.com/2011/05/06/compile-time-computations/ http://akrzemi1.wordpress.com/2011/05/06/compile-time-comput...
- hythloday 15y agoThanks for both your and pdw's explanations...the lovely thing about C++ is that there's always something new to learn. ;)
- pdw 15y agoIt's valid in all versions of C++, I believe. It's usually motivated with a chained ternary operator: return a == ALPHA ? x : a == BETA ? y : a == GAMMA ? z : throw ...; Although that's not a style I'd recommend.