Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / g++.dg / template / sfinae4.C
bloba9650511e9dd698c40c3787aba5b3c3901a38de2
1 // DR 339
2 //
3 // Test of the use of free functions with SFINAE
4 void foo(int) { }
5 template<typename T> void foo(T*) { }
7 typedef char yes_type;
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> { };
15 template<typename T> 
16   typename enable_if<(sizeof(foo(create_a<T const&>()), 1) > 0),
17                      yes_type>::type
18   check_has_foo(const volatile T&);
20 no_type check_has_foo(...);
22 template<typename T>
23 struct has_foo
25   static const bool value = 
26     (sizeof(check_has_foo(create_a<T const&>())) == sizeof(yes_type));
29 struct X { };
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];