OSDN Git Service

/cp
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / template / sfinae4.C
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*) { }
6
7 typedef char yes_type;
8 struct no_type { char data[2]; };
9
10 template<typename T> T create_a();
11
12 template<bool, typename T = void> struct enable_if { typedef T type; };
13 template<typename T> struct enable_if<false, T> { };
14
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&);
19
20 no_type check_has_foo(...);
21
22 template<typename T>
23 struct has_foo
24 {
25   static const bool value = 
26     (sizeof(check_has_foo(create_a<T const&>())) == sizeof(yes_type));
27 };
28
29 struct X { };
30
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];