3 // Test of the use of the ternary operator with SFINAE
7 struct no_type { char data[2]; };
9 template<typename T> T create_a();
10 template<typename T> struct type { };
12 template<bool, typename T = void> struct enable_if { typedef T type; };
13 template<typename T> struct enable_if<false, T> { };
15 #define JOIN( X, Y ) DO_JOIN( X, Y )
16 #define DO_JOIN( X, Y ) DO_JOIN2(X,Y)
17 #define DO_JOIN2( X, Y ) X##Y
19 template<typename T, typename U, typename V>
21 (sizeof((create_a<T>()? create_a<U>() : create_a<V>()), 0) > 0),
25 template<typename T, typename U, typename V> no_type check_ternary(...);
27 template<typename T, typename U, typename V>
30 static const bool value =
31 (sizeof(check_ternary<T, U, V>(0)) == sizeof(yes_type));
34 #ifdef __GXX_EXPERIMENTAL_CXX0X__
35 # define STATIC_ASSERT(Expr) static_assert(Expr, #Expr)
37 # define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1]
41 struct Y { operator bool(); };
43 STATIC_ASSERT((has_ternary<int, float, double>::value));
44 STATIC_ASSERT((has_ternary<bool, double, double>::value));
45 STATIC_ASSERT((!has_ternary<int, float*, double>::value));
46 STATIC_ASSERT((!has_ternary<X, double, double>::value));
47 STATIC_ASSERT((has_ternary<Y, double, double>::value));