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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [template/] [sfinae7.C] - Blame information for rev 801

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

Line No. Rev Author Line
1 693 jeremybenn
// DR 339
2
//
3
// Test of the use of various 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
#define DEFINE_INFIX_BINARY_TRAIT(Name,Op)                              \
20
template                                        \
21
  typename enable_if<(sizeof(create_a() Op create_a(), 1) > 0),  \
22
                     yes_type>::type                                    \
23
  JOIN(check_,Name)(type, type);                                        \
24
                                                                        \
25
no_type JOIN(check_,Name)(...);                                         \
26
                                                                        \
27
template                                        \
28
struct Name                                                             \
29
{                                                                       \
30
  static const bool value =                                             \
31
    (sizeof(JOIN(check_,Name)(type(), type())) == sizeof(yes_type)); \
32
}
33
 
34
template
35
  typename enable_if<(sizeof(create_a()[create_a()], 1) > 0),
36
                     yes_type>::type
37
  check_subscript(int);
38
 
39
template
40
  no_type check_subscript(...);
41
 
42
template
43
struct can_subscript
44
{
45
  static const bool value =
46
    (sizeof(check_subscript(0)) == sizeof(yes_type));
47
};
48
 
49
#ifdef __GXX_EXPERIMENTAL_CXX0X__
50
#  define STATIC_ASSERT(Expr) static_assert(Expr, #Expr)
51
#else
52
#  define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1]
53
#endif
54
 
55
struct X { };
56
struct Y { int operator[](X); };
57
 
58
// is_addable
59
DEFINE_INFIX_BINARY_TRAIT(is_addable, +);
60
X operator+(X, X);
61
X operator+(X, Y);
62
STATIC_ASSERT((is_addable::value));
63
STATIC_ASSERT((is_addable::value));
64
STATIC_ASSERT((is_addable::value));
65
STATIC_ASSERT((is_addable::value));
66
STATIC_ASSERT((!is_addable::value));
67
STATIC_ASSERT((is_addable::value));
68
STATIC_ASSERT((!is_addable::value));
69
 
70
// is_subtractable
71
DEFINE_INFIX_BINARY_TRAIT(is_subtractable, -);
72
X operator-(X, X);
73
X operator-(X, Y);
74
STATIC_ASSERT((is_subtractable::value));
75
STATIC_ASSERT((is_subtractable::value));
76
STATIC_ASSERT((is_subtractable::value));
77
STATIC_ASSERT((is_subtractable::value));
78
STATIC_ASSERT((is_subtractable::value));
79
STATIC_ASSERT((is_subtractable::value));
80
STATIC_ASSERT((!is_subtractable::value));
81
STATIC_ASSERT((!is_subtractable::value));
82
 
83
// is_multiplicable
84
DEFINE_INFIX_BINARY_TRAIT(is_multiplicable, *);
85
X operator*(X, X);
86
X operator*(X, Y);
87
STATIC_ASSERT((is_multiplicable::value));
88
STATIC_ASSERT((is_multiplicable::value));
89
STATIC_ASSERT((is_multiplicable::value));
90
STATIC_ASSERT((!is_multiplicable::value));
91
STATIC_ASSERT((!is_multiplicable::value));
92
STATIC_ASSERT((is_multiplicable::value));
93
STATIC_ASSERT((!is_multiplicable::value));
94
STATIC_ASSERT((!is_multiplicable::value));
95
 
96
// is_divisible
97
DEFINE_INFIX_BINARY_TRAIT(is_divisible, /);
98
X operator/(X, X);
99
X operator/(X, Y);
100
STATIC_ASSERT((is_divisible::value));
101
STATIC_ASSERT((is_divisible::value));
102
STATIC_ASSERT((is_divisible::value));
103
STATIC_ASSERT((!is_divisible::value));
104
STATIC_ASSERT((!is_divisible::value));
105
STATIC_ASSERT((is_divisible::value));
106
STATIC_ASSERT((!is_divisible::value));
107
STATIC_ASSERT((!is_divisible::value));
108
 
109
// has_remainder
110
DEFINE_INFIX_BINARY_TRAIT(has_remainder, %);
111
X operator%(X, X);
112
X operator%(X, Y);
113
STATIC_ASSERT((has_remainder::value));
114
STATIC_ASSERT((has_remainder::value));
115
STATIC_ASSERT((!has_remainder::value));
116
STATIC_ASSERT((has_remainder::value));
117
STATIC_ASSERT((!has_remainder::value));
118
STATIC_ASSERT((!has_remainder::value));
119
STATIC_ASSERT((has_remainder::value));
120
STATIC_ASSERT((!has_remainder::value));
121
STATIC_ASSERT((!has_remainder::value));
122
 
123
// has_xor
124
DEFINE_INFIX_BINARY_TRAIT(has_xor, ^);
125
X operator^(X, X);
126
X operator^(X, Y);
127
STATIC_ASSERT((has_xor::value));
128
STATIC_ASSERT((has_xor::value));
129
STATIC_ASSERT((!has_xor::value));
130
STATIC_ASSERT((has_xor::value));
131
STATIC_ASSERT((!has_xor::value));
132
STATIC_ASSERT((!has_xor::value));
133
STATIC_ASSERT((has_xor::value));
134
STATIC_ASSERT((!has_xor::value));
135
STATIC_ASSERT((!has_xor::value));
136
 
137
// has_bitand
138
DEFINE_INFIX_BINARY_TRAIT(has_bitand, &);
139
X operator&(X, X);
140
X operator&(X, Y);
141
STATIC_ASSERT((has_bitand::value));
142
STATIC_ASSERT((has_bitand::value));
143
STATIC_ASSERT((!has_bitand::value));
144
STATIC_ASSERT((has_bitand::value));
145
STATIC_ASSERT((!has_bitand::value));
146
STATIC_ASSERT((!has_bitand::value));
147
STATIC_ASSERT((has_bitand::value));
148
STATIC_ASSERT((!has_bitand::value));
149
STATIC_ASSERT((!has_bitand::value));
150
 
151
// has_bitor
152
DEFINE_INFIX_BINARY_TRAIT(has_bitor, |);
153
X operator|(X, X);
154
X operator|(X, Y);
155
STATIC_ASSERT((has_bitor::value));
156
STATIC_ASSERT((has_bitor::value));
157
STATIC_ASSERT((!has_bitor::value));
158
STATIC_ASSERT((has_bitor::value));
159
STATIC_ASSERT((!has_bitor::value));
160
STATIC_ASSERT((!has_bitor::value));
161
STATIC_ASSERT((has_bitor::value));
162
STATIC_ASSERT((!has_bitor::value));
163
STATIC_ASSERT((!has_bitor::value));
164
 
165
// has_left_shift
166
DEFINE_INFIX_BINARY_TRAIT(has_left_shift, <<);
167
X operator<<(X, X);
168
X operator<<(X, Y);
169
STATIC_ASSERT((has_left_shift::value));
170
STATIC_ASSERT((has_left_shift::value));
171
STATIC_ASSERT((!has_left_shift::value));
172
STATIC_ASSERT((has_left_shift::value));
173
STATIC_ASSERT((!has_left_shift::value));
174
STATIC_ASSERT((!has_left_shift::value));
175
STATIC_ASSERT((has_left_shift::value));
176
STATIC_ASSERT((!has_left_shift::value));
177
STATIC_ASSERT((!has_left_shift::value));
178
 
179
// has_right_shift
180
DEFINE_INFIX_BINARY_TRAIT(has_right_shift, >>);
181
X operator>>(X, X);
182
X operator>>(X, Y);
183
STATIC_ASSERT((has_right_shift::value));
184
STATIC_ASSERT((has_right_shift::value));
185
STATIC_ASSERT((!has_right_shift::value));
186
STATIC_ASSERT((has_right_shift::value));
187
STATIC_ASSERT((!has_right_shift::value));
188
STATIC_ASSERT((!has_right_shift::value));
189
STATIC_ASSERT((has_right_shift::value));
190
STATIC_ASSERT((!has_right_shift::value));
191
STATIC_ASSERT((!has_right_shift::value));
192
 
193
// can_subscript
194
STATIC_ASSERT((can_subscript::value));
195
STATIC_ASSERT((can_subscript::value));
196
STATIC_ASSERT((can_subscript::value));
197
STATIC_ASSERT((can_subscript::value));
198
STATIC_ASSERT((!can_subscript::value));
199
STATIC_ASSERT((can_subscript::value));

powered by: WebSVN 2.1.0

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