以下のコードはwell-formedなC++0xのコードである。
int f()
{ return 0 ; }
template < int x >
struct Foo {} ;
Foo< true ? 0 : f() > foo ;
constexpr int x = true ? 0 : f() ;
f()は定数式ではないが、この場合、評価されない。つまり、この初期化式は、定数式である。falseの場合は、コンパイルエラーである。
これはC++0xの変更点である。C++03では、trueでもエラーになる。
このルールは、Conditinal operatorの他にも、logical AND operator, logical OR operatorにも適用される。
No comments:
Post a Comment