1// DR 339 2// 3// Test of the use of the function call operator with SFINAE 4typedef char yes_type; 5struct no_type { char data[2]; }; 6 7template<typename T> T create_a(); 8 9template<typename T> struct type { }; 10 11template<bool, typename T = void> struct enable_if { typedef T type; }; 12template<typename T> struct enable_if<false, T> { }; 13 14template<typename F, typename T1, typename T2> 15 typename enable_if<sizeof(create_a<F>()(create_a<T1>(), create_a<T2>()), 1), 16 yes_type>::type 17 check_is_callable2(type<F>, type<T1>, type<T2>); 18 19no_type check_is_callable2(...); 20 21template<typename F, typename T1, typename T2 = T1> 22struct is_callable2 23{ 24 static const bool value = 25 (sizeof(check_is_callable2(type<F>(), type<T1>(), type<T2>())) 26 == sizeof(yes_type)); 27}; 28 29#define JOIN( X, Y ) DO_JOIN( X, Y ) 30#define DO_JOIN( X, Y ) DO_JOIN2(X,Y) 31#define DO_JOIN2( X, Y ) X##Y 32 33#ifdef __GXX_EXPERIMENTAL_CXX0X__ 34# define STATIC_ASSERT(Expr) static_assert(Expr, #Expr) 35#else 36# define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1] 37#endif 38 39 40struct A; 41struct B; 42 43struct A { 44 A(B); 45}; 46 47struct B { 48 B(A); 49}; 50 51struct F1 { }; 52 53struct F2 { 54 bool operator()(int, float); 55}; 56 57struct F3 { 58 bool operator()(int); 59}; 60 61struct F4 { 62 void operator()(A, A); 63 void operator()(B, B); 64}; 65 66struct F5 { 67 void operator()(A, A); 68 69private: 70 void operator()(B, B); 71}; 72 73STATIC_ASSERT((is_callable2<int(*)(int, int), long, int>::value)); 74STATIC_ASSERT((!is_callable2<int(*)(int, int), int*, int>::value)); 75STATIC_ASSERT((!is_callable2<F1, int, int>::value)); 76STATIC_ASSERT((is_callable2<F2, int, int>::value)); 77STATIC_ASSERT((!is_callable2<F2, int*, int>::value)); 78STATIC_ASSERT((!is_callable2<F3, int, int>::value)); 79STATIC_ASSERT((is_callable2<F4, A, A>::value)); 80STATIC_ASSERT((is_callable2<F4, B, B>::value)); 81STATIC_ASSERT((!is_callable2<F4, A, B>::value)); 82STATIC_ASSERT((is_callable2<F5, A, A>::value)); 83STATIC_ASSERT((!is_callable2<F5, A, B>::value)); 84