OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [g++.dg/] [template/] [sfinae8.C] - Blame information for rev 307

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 301 jeremybenn
// DR 339
2
//
3
// Test of the use of various boolean binary operators with SFINAE
4
 
5
// Boilerplate helpers
6
typedef char yes_type;
7
struct no_type { char data[2]; };
8
 
9
template T create_a();
10
template struct type { };
11
 
12
template struct enable_if { typedef T type; };
13
template struct enable_if { };
14
 
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
18
 
19
bool accepts_bool(bool);
20
 
21
#define DEFINE_BINARY_PREDICATE_TRAIT(Name,Op)                          \
22
template                                        \
23
  typename enable_if() Op create_a())), \
24
                     yes_type>::type                                    \
25
  JOIN(check_,Name)(type, type);                                        \
26
                                                                        \
27
no_type JOIN(check_,Name)(...);                                         \
28
                                                                        \
29
template                                        \
30
struct Name                                                             \
31
{                                                                       \
32
  static const bool value =                                             \
33
    (sizeof(JOIN(check_,Name)(type(), type())) == sizeof(yes_type)); \
34
}
35
 
36
#ifdef __GXX_EXPERIMENTAL_CXX0X__
37
#  define STATIC_ASSERT(Expr) static_assert(Expr, #Expr)
38
#else
39
#  define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1]
40
#endif
41
 
42
struct X { };
43
struct Y { };
44
 
45
struct convertible_to_bool {
46
  operator int convertible_to_bool::* ();
47
};
48
 
49
struct not_convertible_to_bool { };
50
 
51
// is_less_than_comparable
52
DEFINE_BINARY_PREDICATE_TRAIT(is_less_than_comparable,<);
53
bool                    operator<(X, X);
54
convertible_to_bool     operator<(X, Y);
55
not_convertible_to_bool operator<(Y, X);
56
 
57
STATIC_ASSERT((is_less_than_comparable::value));
58
STATIC_ASSERT((is_less_than_comparable::value));
59
STATIC_ASSERT((is_less_than_comparable::value));
60
STATIC_ASSERT((is_less_than_comparable::value));
61
STATIC_ASSERT((is_less_than_comparable::value));
62
STATIC_ASSERT((!is_less_than_comparable::value));
63
STATIC_ASSERT((!is_less_than_comparable::value));
64
 
65
// is_less_equal_comparable
66
DEFINE_BINARY_PREDICATE_TRAIT(is_less_equal_comparable,<=);
67
bool                    operator<=(X, X);
68
convertible_to_bool     operator<=(X, Y);
69
not_convertible_to_bool operator<=(Y, X);
70
 
71
STATIC_ASSERT((is_less_equal_comparable::value));
72
STATIC_ASSERT((is_less_equal_comparable::value));
73
STATIC_ASSERT((is_less_equal_comparable::value));
74
STATIC_ASSERT((is_less_equal_comparable::value));
75
STATIC_ASSERT((is_less_equal_comparable::value));
76
STATIC_ASSERT((!is_less_equal_comparable::value));
77
STATIC_ASSERT((!is_less_equal_comparable::value));
78
 
79
// is_greater_than_comparable
80
DEFINE_BINARY_PREDICATE_TRAIT(is_greater_than_comparable,>);
81
bool                    operator>(X, X);
82
convertible_to_bool     operator>(X, Y);
83
not_convertible_to_bool operator>(Y, X);
84
 
85
STATIC_ASSERT((is_greater_than_comparable::value));
86
STATIC_ASSERT((is_greater_than_comparable::value));
87
STATIC_ASSERT((is_greater_than_comparable::value));
88
STATIC_ASSERT((is_greater_than_comparable::value));
89
STATIC_ASSERT((is_greater_than_comparable::value));
90
STATIC_ASSERT((!is_greater_than_comparable::value));
91
STATIC_ASSERT((!is_greater_than_comparable::value));
92
 
93
// is_greater_equal_comparable
94
DEFINE_BINARY_PREDICATE_TRAIT(is_greater_equal_comparable,>=);
95
bool                    operator>=(X, X);
96
convertible_to_bool     operator>=(X, Y);
97
not_convertible_to_bool operator>=(Y, X);
98
 
99
STATIC_ASSERT((is_greater_equal_comparable::value));
100
STATIC_ASSERT((is_greater_equal_comparable::value));
101
STATIC_ASSERT((is_greater_equal_comparable::value));
102
STATIC_ASSERT((is_greater_equal_comparable::value));
103
STATIC_ASSERT((is_greater_equal_comparable::value));
104
STATIC_ASSERT((!is_greater_equal_comparable::value));
105
STATIC_ASSERT((!is_greater_equal_comparable::value));
106
 
107
// is_equality_comparable
108
struct Z : X { };
109
DEFINE_BINARY_PREDICATE_TRAIT(is_equality_comparable,==);
110
bool                    operator==(X, X);
111
convertible_to_bool     operator==(X, Y);
112
not_convertible_to_bool operator==(Y, X);
113
 
114
STATIC_ASSERT((is_equality_comparable::value));
115
STATIC_ASSERT((is_equality_comparable::value));
116
STATIC_ASSERT((is_equality_comparable::value));
117
STATIC_ASSERT((is_equality_comparable::value));
118
STATIC_ASSERT((is_equality_comparable::value));
119
STATIC_ASSERT((!is_equality_comparable::value));
120
STATIC_ASSERT((!is_equality_comparable::value));
121
STATIC_ASSERT((is_equality_comparable::value));
122
STATIC_ASSERT((!is_equality_comparable::value));
123
STATIC_ASSERT((is_equality_comparable::value));
124
STATIC_ASSERT((is_equality_comparable::value));
125
STATIC_ASSERT((!is_equality_comparable::value));
126
 
127
// is_not_equal_comparable
128
DEFINE_BINARY_PREDICATE_TRAIT(is_not_equal_comparable,!=);
129
bool                    operator!=(X, X);
130
convertible_to_bool     operator!=(X, Y);
131
not_convertible_to_bool operator!=(Y, X);
132
 
133
STATIC_ASSERT((is_not_equal_comparable::value));
134
STATIC_ASSERT((is_not_equal_comparable::value));
135
STATIC_ASSERT((is_not_equal_comparable::value));
136
STATIC_ASSERT((is_not_equal_comparable::value));
137
STATIC_ASSERT((is_not_equal_comparable::value));
138
STATIC_ASSERT((!is_not_equal_comparable::value));
139
STATIC_ASSERT((!is_not_equal_comparable::value));
140
STATIC_ASSERT((is_not_equal_comparable::value));
141
STATIC_ASSERT((!is_not_equal_comparable::value));
142
STATIC_ASSERT((is_not_equal_comparable::value));
143
STATIC_ASSERT((is_not_equal_comparable::value));
144
STATIC_ASSERT((!is_not_equal_comparable::value));
145
 
146
// has_logical_and
147
DEFINE_BINARY_PREDICATE_TRAIT(has_logical_and,&&);
148
bool                    operator&&(X, X);
149
convertible_to_bool     operator&&(X, Y);
150
not_convertible_to_bool operator&&(Y, X);
151
 
152
STATIC_ASSERT((has_logical_and::value));
153
STATIC_ASSERT((has_logical_and::value));
154
STATIC_ASSERT((has_logical_and::value));
155
STATIC_ASSERT((has_logical_and::value));
156
STATIC_ASSERT((has_logical_and::value));
157
STATIC_ASSERT((!has_logical_and::value));
158
STATIC_ASSERT((!has_logical_and::value));
159
STATIC_ASSERT((has_logical_and::value));
160
STATIC_ASSERT((has_logical_and::value));
161
STATIC_ASSERT((has_logical_and::value));
162
STATIC_ASSERT((has_logical_and::value));
163
STATIC_ASSERT((has_logical_and::value));
164
 
165
// has_logical_or
166
DEFINE_BINARY_PREDICATE_TRAIT(has_logical_or,||);
167
bool                    operator||(X, X);
168
convertible_to_bool     operator||(X, Y);
169
not_convertible_to_bool operator||(Y, X);
170
 
171
STATIC_ASSERT((has_logical_or::value));
172
STATIC_ASSERT((has_logical_or::value));
173
STATIC_ASSERT((has_logical_or::value));
174
STATIC_ASSERT((has_logical_or::value));
175
STATIC_ASSERT((has_logical_or::value));
176
STATIC_ASSERT((!has_logical_or::value));
177
STATIC_ASSERT((!has_logical_or::value));
178
STATIC_ASSERT((has_logical_or::value));
179
STATIC_ASSERT((has_logical_or::value));
180
STATIC_ASSERT((has_logical_or::value));
181
STATIC_ASSERT((has_logical_or::value));
182
STATIC_ASSERT((has_logical_or::value));

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.