3 // Test of the use of free functions with SFINAE
5 template<typename T> void foo(T*) { }
8 struct no_type { char data[2]; };
10 template<typename T> T create_a();
12 template<bool, typename T = void> struct enable_if { typedef T type; };
13 template<typename T> struct enable_if<false, T> { };
16 typename enable_if<(sizeof(foo(create_a<T const&>()), 1) > 0),
18 check_has_foo(const volatile T&);
20 no_type check_has_foo(...);
25 static const bool value =
26 (sizeof(check_has_foo(create_a<T const&>())) == sizeof(yes_type));
31 int a1[has_foo<int>::value? 1 : -1];
32 int a2[has_foo<long>::value? 1 : -1];
33 int a3[has_foo<int*>::value? 1 : -1];
34 int a4[has_foo<X>::value? -1 : 1];
35 int a5[has_foo<int X::*>::value? -1 : 1];