summaryrefslogtreecommitdiff
path: root/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp
blob: fc01b22c36abe822cd0876b9206118fe60d74828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// <functional>

// result_of<Fn(ArgTypes...)>

#include <type_traits>
#include <memory>
#include <cassert>
#include "test_macros.h"

struct S
{
    typedef short (*FreeFunc)(long);
    operator FreeFunc() const;
    double operator()(char, int&);
    double const& operator()(char, int&) const;
    double volatile& operator()(char, int&) volatile;
    double const volatile& operator()(char, int&) const volatile;
};


struct SD : public S { };

struct NotDerived {};

template <class Tp>
struct Voider {
    typedef void type;
};

template <class T, class = void>
struct HasType : std::false_type {};

template <class T>
struct HasType<T, typename Voider<typename T::type>::type> : std::true_type {};

template <class T, class U>
void test_result_of()
{
#if TEST_STD_VER > 14
    static_assert(std::is_callable<T>::value, "");
    static_assert(std::is_callable<T, U>::value, "");
#endif
    static_assert((std::is_same<typename std::result_of<T>::type, U>::value), "");
}

template <class T>
void test_no_result()
{
#if TEST_STD_VER >= 11
    static_assert((!HasType<std::result_of<T> >::value), "");
#endif
#if TEST_STD_VER > 14
    static_assert(std::is_callable<T>::value == false, "");
#endif
}

int main()
{
    typedef NotDerived ND;
    { // functor object
    test_result_of<S(int), short> ();
    test_result_of<S&(unsigned char, int&), double> ();
    test_result_of<S const&(unsigned char, int&), double const &> ();
    test_result_of<S volatile&(unsigned char, int&), double volatile&> ();
    test_result_of<S const volatile&(unsigned char, int&), double const volatile&> ();
    }
    { // pointer to function
    typedef bool         (&RF0)();
    typedef bool*       (&RF1)(int);
    typedef bool&       (&RF2)(int, int);
    typedef bool const& (&RF3)(int, int, int);
    typedef bool        (*PF0)();
    typedef bool*       (*PF1)(int);
    typedef bool&       (*PF2)(int, int);
    typedef bool const& (*PF3)(int, int, int);
    typedef bool        (*&PRF0)();
    typedef bool*       (*&PRF1)(int);
    typedef bool&       (*&PRF2)(int, int);
    typedef bool const& (*&PRF3)(int, int, int);
    test_result_of<RF0(), bool>();
    test_result_of<RF1(int), bool*>();
    test_result_of<RF2(int, long), bool&>();
    test_result_of<RF3(int, long, int), bool const&>();
    test_result_of<PF0(), bool>();
    test_result_of<PF1(int), bool*>();
    test_result_of<PF2(int, long), bool&>();
    test_result_of<PF3(int, long, int), bool const&>();
    test_result_of<PRF0(), bool>();
    test_result_of<PRF1(int), bool*>();
    test_result_of<PRF2(int, long), bool&>();
    test_result_of<PRF3(int, long, int), bool const&>();
    }
    { // pointer to member function

    typedef int         (S::*PMS0)();
    typedef int*        (S::*PMS1)(long);
    typedef int&        (S::*PMS2)(long, int);
    test_result_of<PMS0(                             S),   int> ();
    test_result_of<PMS0(                             S&),  int> ();
    test_result_of<PMS0(                             S*),  int> ();
    test_result_of<PMS0(                             S*&), int> ();
    test_result_of<PMS0(      std::reference_wrapper<S>),  int> ();
    test_result_of<PMS0(const std::reference_wrapper<S>&), int> ();
    test_result_of<PMS0(      std::reference_wrapper<SD>),  int> ();
    test_result_of<PMS0(const std::reference_wrapper<SD>&), int> ();
    test_result_of<PMS0(std::unique_ptr<S>),  int> ();
    test_result_of<PMS0(std::unique_ptr<SD>), int> ();
    test_no_result<PMS0(const          S&)>();
    test_no_result<PMS0(volatile       S&)>();
    test_no_result<PMS0(const volatile S&)>();
    test_no_result<PMS0(ND &                           )>();
    test_no_result<PMS0(const ND&                      )>();
    test_no_result<PMS0(std::unique_ptr<S const>       )>();
    test_no_result<PMS0(std::reference_wrapper<S const>)>();
    test_no_result<PMS0(std::reference_wrapper<ND>     )>();
    test_no_result<PMS0(std::unique_ptr<ND>            )>();

    test_result_of<PMS1(                             S,   int), int*> ();
    test_result_of<PMS1(                             S&,  int), int*> ();
    test_result_of<PMS1(                             S*,  int), int*> ();
    test_result_of<PMS1(                             S*&, int), int*> ();
    test_result_of<PMS1(std::unique_ptr<S>,               int), int*> ();
    test_result_of<PMS1(std::unique_ptr<SD>,              int), int*> ();
    test_result_of<PMS1(std::reference_wrapper<S>,        int), int*> ();
    test_result_of<PMS1(const std::reference_wrapper<S>&, int), int*> ();
    test_result_of<PMS1(std::reference_wrapper<SD>,        int), int*> ();
    test_result_of<PMS1(const std::reference_wrapper<SD>&, int), int*> ();
    test_no_result<PMS1(const          S&, int)>();
    test_no_result<PMS1(volatile       S&, int)>();
    test_no_result<PMS1(const volatile S&, int)>();
    test_no_result<PMS1(ND &,                            int)>();
    test_no_result<PMS1(const ND&,                       int)>();
    test_no_result<PMS1(std::unique_ptr<S const>,        int)>();
    test_no_result<PMS1(std::reference_wrapper<S const>, int)>();
    test_no_result<PMS1(std::reference_wrapper<ND>,      int)>();
    test_no_result<PMS1(std::unique_ptr<ND>,             int)>();

    test_result_of<PMS2(               S,   int, int), int&> ();
    test_result_of<PMS2(               S&,  int, int), int&> ();
    test_result_of<PMS2(               S*,  int, int), int&> ();
    test_result_of<PMS2(               S*&, int, int), int&> ();
    test_result_of<PMS2(std::unique_ptr<S>, int, int), int&> ();
    test_result_of<PMS2(std::unique_ptr<SD>, int, int), int&> ();
    test_result_of<PMS2(std::reference_wrapper<S>,         int, int), int&> ();
    test_result_of<PMS2(const std::reference_wrapper<S>&,  int, int), int&> ();
    test_result_of<PMS2(std::reference_wrapper<SD>,        int, int), int&> ();
    test_result_of<PMS2(const std::reference_wrapper<SD>&, int, int), int&> ();
    test_no_result<PMS2(const          S&, int, int)>();
    test_no_result<PMS2(volatile       S&, int, int)>();
    test_no_result<PMS2(const volatile S&, int, int)>();
    test_no_result<PMS2(std::unique_ptr<S const>,   int, int)>();
    test_no_result<PMS2(std::reference_wrapper<S const>, int, int)>();
    test_no_result<PMS2(const ND&,                  int, int)>();
    test_no_result<PMS2(std::reference_wrapper<ND>, int, int)>();
    test_no_result<PMS2(std::unique_ptr<ND>,        int, int)>();

    typedef int        (S::*PMS0C)() const;
    typedef int*       (S::*PMS1C)(long) const;
    typedef int&       (S::*PMS2C)(long, int) const;
    test_result_of<PMS0C(               S),   int> ();
    test_result_of<PMS0C(               S&),  int> ();
    test_result_of<PMS0C(const          S&),  int> ();
    test_result_of<PMS0C(               S*),  int> ();
    test_result_of<PMS0C(const          S*),  int> ();
    test_result_of<PMS0C(               S*&), int> ();
    test_result_of<PMS0C(const          S*&), int> ();
    test_result_of<PMS0C(std::unique_ptr<S>), int> ();
    test_result_of<PMS0C(std::unique_ptr<SD>), int> ();
    test_result_of<PMS0C(std::reference_wrapper<S>              ), int> ();
    test_result_of<PMS0C(std::reference_wrapper<const S>        ), int> ();
    test_result_of<PMS0C(const std::reference_wrapper<S> &      ), int> ();
    test_result_of<PMS0C(const std::reference_wrapper<const S> &), int> ();
    test_result_of<PMS0C(std::reference_wrapper<SD>             ), int> ();
    test_result_of<PMS0C(std::reference_wrapper<const SD>       ), int> ();
    test_result_of<PMS0C(const std::reference_wrapper<SD> &     ), int> ();
    test_result_of<PMS0C(const std::reference_wrapper<const SD> &), int> ();
    test_no_result<PMS0C(volatile       S&)>();
    test_no_result<PMS0C(const volatile S&)>();

    test_result_of<PMS1C(               S,   int), int*> ();
    test_result_of<PMS1C(               S&,  int), int*> ();
    test_result_of<PMS1C(const          S&,  int), int*> ();
    test_result_of<PMS1C(               S*,  int), int*> ();
    test_result_of<PMS1C(const          S*,  int), int*> ();
    test_result_of<PMS1C(               S*&, int), int*> ();
    test_result_of<PMS1C(const          S*&, int), int*> ();
    test_result_of<PMS1C(std::unique_ptr<S>, int), int*> ();
    test_no_result<PMS1C(volatile       S&, int)>();
    test_no_result<PMS1C(const volatile S&, int)>();

    test_result_of<PMS2C(               S,   int, int), int&> ();
    test_result_of<PMS2C(               S&,  int, int), int&> ();
    test_result_of<PMS2C(const          S&,  int, int), int&> ();
    test_result_of<PMS2C(               S*,  int, int), int&> ();
    test_result_of<PMS2C(const          S*,  int, int), int&> ();
    test_result_of<PMS2C(               S*&, int, int), int&> ();
    test_result_of<PMS2C(const          S*&, int, int), int&> ();
    test_result_of<PMS2C(std::unique_ptr<S>, int, int), int&> ();
    test_no_result<PMS2C(volatile       S&, int, int)>();
    test_no_result<PMS2C(const volatile S&, int, int)>();

    typedef int       (S::*PMS0V)() volatile;
    typedef int*       (S::*PMS1V)(long) volatile;
    typedef int&       (S::*PMS2V)(long, int) volatile;
    test_result_of<PMS0V(               S),   int> ();
    test_result_of<PMS0V(               S&),  int> ();
    test_result_of<PMS0V(volatile       S&),  int> ();
    test_result_of<PMS0V(               S*),  int> ();
    test_result_of<PMS0V(volatile       S*),  int> ();
    test_result_of<PMS0V(               S*&), int> ();
    test_result_of<PMS0V(volatile       S*&), int> ();
    test_result_of<PMS0V(std::unique_ptr<S>), int> ();
    test_no_result<PMS0V(const          S&)>();
    test_no_result<PMS0V(const volatile S&)>();

    test_result_of<PMS1V(               S,   int), int*> ();
    test_result_of<PMS1V(               S&,  int), int*> ();
    test_result_of<PMS1V(volatile       S&,  int), int*> ();
    test_result_of<PMS1V(               S*,  int), int*> ();
    test_result_of<PMS1V(volatile       S*,  int), int*> ();
    test_result_of<PMS1V(               S*&, int), int*> ();
    test_result_of<PMS1V(volatile       S*&, int), int*> ();
    test_result_of<PMS1V(std::unique_ptr<S>, int), int*> ();
    test_no_result<PMS1V(const          S&, int)>();
    test_no_result<PMS1V(const volatile S&, int)>();

    test_result_of<PMS2V(               S,   int, int), int&> ();
    test_result_of<PMS2V(               S&,  int, int), int&> ();
    test_result_of<PMS2V(volatile       S&,  int, int), int&> ();
    test_result_of<PMS2V(               S*,  int, int), int&> ();
    test_result_of<PMS2V(volatile       S*,  int, int), int&> ();
    test_result_of<PMS2V(               S*&, int, int), int&> ();
    test_result_of<PMS2V(volatile       S*&, int, int), int&> ();
    test_result_of<PMS2V(std::unique_ptr<S>, int, int), int&> ();
    test_no_result<PMS2V(const          S&, int, int)>();
    test_no_result<PMS2V(const volatile S&, int, int)>();

    typedef int        (S::*PMS0CV)() const volatile;
    typedef int*       (S::*PMS1CV)(long) const volatile;
    typedef int&       (S::*PMS2CV)(long, int) const volatile;
    test_result_of<PMS0CV(               S),   int> ();
    test_result_of<PMS0CV(               S&),  int> ();
    test_result_of<PMS0CV(const          S&),  int> ();
    test_result_of<PMS0CV(volatile       S&),  int> ();
    test_result_of<PMS0CV(const volatile S&),  int> ();
    test_result_of<PMS0CV(               S*),  int> ();
    test_result_of<PMS0CV(const          S*),  int> ();
    test_result_of<PMS0CV(volatile       S*),  int> ();
    test_result_of<PMS0CV(const volatile S*),  int> ();
    test_result_of<PMS0CV(               S*&), int> ();
    test_result_of<PMS0CV(const          S*&), int> ();
    test_result_of<PMS0CV(volatile       S*&), int> ();
    test_result_of<PMS0CV(const volatile S*&), int> ();
    test_result_of<PMS0CV(std::unique_ptr<S>), int> ();

    test_result_of<PMS1CV(               S,   int), int*> ();
    test_result_of<PMS1CV(               S&,  int), int*> ();
    test_result_of<PMS1CV(const          S&,  int), int*> ();
    test_result_of<PMS1CV(volatile       S&,  int), int*> ();
    test_result_of<PMS1CV(const volatile S&,  int), int*> ();
    test_result_of<PMS1CV(               S*,  int), int*> ();
    test_result_of<PMS1CV(const          S*,  int), int*> ();
    test_result_of<PMS1CV(volatile       S*,  int), int*> ();
    test_result_of<PMS1CV(const volatile S*,  int), int*> ();
    test_result_of<PMS1CV(               S*&, int), int*> ();
    test_result_of<PMS1CV(const          S*&, int), int*> ();
    test_result_of<PMS1CV(volatile       S*&, int), int*> ();
    test_result_of<PMS1CV(const volatile S*&, int), int*> ();
    test_result_of<PMS1CV(std::unique_ptr<S>, int), int*> ();

    test_result_of<PMS2CV(               S,   int, int), int&> ();
    test_result_of<PMS2CV(               S&,  int, int), int&> ();
    test_result_of<PMS2CV(const          S&,  int, int), int&> ();
    test_result_of<PMS2CV(volatile       S&,  int, int), int&> ();
    test_result_of<PMS2CV(const volatile S&,  int, int), int&> ();
    test_result_of<PMS2CV(               S*,  int, int), int&> ();
    test_result_of<PMS2CV(const          S*,  int, int), int&> ();
    test_result_of<PMS2CV(volatile       S*,  int, int), int&> ();
    test_result_of<PMS2CV(const volatile S*,  int, int), int&> ();
    test_result_of<PMS2CV(               S*&, int, int), int&> ();
    test_result_of<PMS2CV(const          S*&, int, int), int&> ();
    test_result_of<PMS2CV(volatile       S*&, int, int), int&> ();
    test_result_of<PMS2CV(const volatile S*&, int, int), int&> ();
    test_result_of<PMS2CV(std::unique_ptr<S>, int, int), int&> ();
    }
    { // pointer to member data
    typedef char S::*PMD;
    test_result_of<PMD(S&), char &>();
    test_result_of<PMD(S*), char &>();
    test_result_of<PMD(S* const), char &>();
    test_result_of<PMD(const S&), const char&> ();
    test_result_of<PMD(const S*), const char&> ();
    test_result_of<PMD(volatile S&), volatile char&> ();
    test_result_of<PMD(volatile S*), volatile char&> ();
    test_result_of<PMD(const volatile S&), const volatile char&> ();
    test_result_of<PMD(const volatile S*), const volatile char&> ();
    test_result_of<PMD(SD&), char &>();
    test_result_of<PMD(SD const&), const char&>();
    test_result_of<PMD(SD*), char&>();
    test_result_of<PMD(const SD*), const char&>();
    test_result_of<PMD(std::unique_ptr<S>), char &>();
    test_result_of<PMD(std::unique_ptr<S const>), const char&>();
#if TEST_STD_VER >= 11
    test_result_of<PMD(std::reference_wrapper<S>), char&>();
    test_result_of<PMD(std::reference_wrapper<S const>), const char&>();
#endif
    test_no_result<PMD(ND&)>();
    }
}