blob: 5a925bb34b260a5a964c4c883c3039416245e4e8 [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// <functional>
11
12// result_of<Fn(ArgTypes...)>
13
14#include <type_traits>
15#include <memory>
Eric Fiselier49835802015-06-13 08:25:24 +000016#include "test_macros.h"
Howard Hinnantc52f43e2010-08-22 00:59:46 +000017
18struct S
19{
Eric Fiselier49835802015-06-13 08:25:24 +000020 typedef short (*FreeFunc)(long);
21 operator FreeFunc() const;
Howard Hinnantc52f43e2010-08-22 00:59:46 +000022 double operator()(char, int&);
Eric Fiselier49835802015-06-13 08:25:24 +000023 double const& operator()(char, int&) const;
24 double volatile& operator()(char, int&) volatile;
25 double const volatile& operator()(char, int&) const volatile;
Howard Hinnantc52f43e2010-08-22 00:59:46 +000026};
27
Eric Fiselier49835802015-06-13 08:25:24 +000028template <class Tp>
29struct Voider {
30 typedef void type;
Howard Hinnantecc97422013-05-07 23:40:12 +000031};
32
Eric Fiselier49835802015-06-13 08:25:24 +000033template <class T, class = void>
34struct HasType : std::false_type {};
35
36template <class T>
37struct HasType<T, typename Voider<typename T::type>::type> : std::true_type {};
Marshall Clow71e699d2014-02-10 17:40:28 +000038
Marshall Clow933afa92013-07-04 00:10:01 +000039template <class T, class U>
Eric Fiselier49835802015-06-13 08:25:24 +000040void test_result_of()
Marshall Clow933afa92013-07-04 00:10:01 +000041{
42 static_assert((std::is_same<typename std::result_of<T>::type, U>::value), "");
Eric Fiselier49835802015-06-13 08:25:24 +000043}
44
45template <class T>
46void test_no_result()
47{
48#if TEST_STD_VER >= 11
49 static_assert((!HasType<std::result_of<T> >::value), "");
Marshall Clow933afa92013-07-04 00:10:01 +000050#endif
51}
52
Howard Hinnantc52f43e2010-08-22 00:59:46 +000053int main()
54{
Eric Fiselier49835802015-06-13 08:25:24 +000055 { // functor object
56 test_result_of<S(int), short> ();
57 test_result_of<S&(unsigned char, int&), double> ();
58 test_result_of<S const&(unsigned char, int&), double const &> ();
59 test_result_of<S volatile&(unsigned char, int&), double volatile&> ();
60 test_result_of<S const volatile&(unsigned char, int&), double const volatile&> ();
61 }
62 { // pointer to function
63 typedef bool (&RF0)();
64 typedef bool* (&RF1)(int);
65 typedef bool& (&RF2)(int, int);
66 typedef bool const& (&RF3)(int, int, int);
67 typedef bool (*PF0)();
68 typedef bool* (*PF1)(int);
69 typedef bool& (*PF2)(int, int);
70 typedef bool const& (*PF3)(int, int, int);
71 typedef bool (*&PRF0)();
72 typedef bool* (*&PRF1)(int);
73 typedef bool& (*&PRF2)(int, int);
74 typedef bool const& (*&PRF3)(int, int, int);
75 test_result_of<RF0(), bool>();
76 test_result_of<RF1(int), bool*>();
77 test_result_of<RF2(int, long), bool&>();
78 test_result_of<RF3(int, long, int), bool const&>();
79 test_result_of<PF0(), bool>();
80 test_result_of<PF1(int), bool*>();
81 test_result_of<PF2(int, long), bool&>();
82 test_result_of<PF3(int, long, int), bool const&>();
83 test_result_of<PRF0(), bool>();
84 test_result_of<PRF1(int), bool*>();
85 test_result_of<PRF2(int, long), bool&>();
86 test_result_of<PRF3(int, long, int), bool const&>();
87 }
88 { // pointer to member function
Marshall Clow933afa92013-07-04 00:10:01 +000089
Eric Fiselier49835802015-06-13 08:25:24 +000090 typedef int (S::*PMS0)();
91 typedef int* (S::*PMS1)(long);
92 typedef int& (S::*PMS2)(long, int);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070093 test_result_of<PMS0( S), int> ();
94 test_result_of<PMS0( S&), int> ();
95 test_result_of<PMS0( S*), int> ();
96 test_result_of<PMS0( S*&), int> ();
97 test_result_of<PMS0(std::unique_ptr<S>), int> ();
Eric Fiselier49835802015-06-13 08:25:24 +000098 test_no_result<PMS0(const S&)>();
99 test_no_result<PMS0(volatile S&)>();
100 test_no_result<PMS0(const volatile S&)>();
101
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700102 test_result_of<PMS1( S, int), int*> ();
103 test_result_of<PMS1( S&, int), int*> ();
104 test_result_of<PMS1( S*, int), int*> ();
105 test_result_of<PMS1( S*&, int), int*> ();
106 test_result_of<PMS1(std::unique_ptr<S>, int), int*> ();
Eric Fiselier49835802015-06-13 08:25:24 +0000107 test_no_result<PMS1(const S&, int)>();
108 test_no_result<PMS1(volatile S&, int)>();
109 test_no_result<PMS1(const volatile S&, int)>();
110
111 test_result_of<PMS2( S, int, int), int&> ();
112 test_result_of<PMS2( S&, int, int), int&> ();
113 test_result_of<PMS2( S*, int, int), int&> ();
114 test_result_of<PMS2( S*&, int, int), int&> ();
115 test_result_of<PMS2(std::unique_ptr<S>, int, int), int&> ();
116 test_no_result<PMS2(const S&, int, int)>();
117 test_no_result<PMS2(volatile S&, int, int)>();
118 test_no_result<PMS2(const volatile S&, int, int)>();
119
120 typedef int (S::*PMS0C)() const;
121 typedef int* (S::*PMS1C)(long) const;
122 typedef int& (S::*PMS2C)(long, int) const;
123 test_result_of<PMS0C( S), int> ();
124 test_result_of<PMS0C( S&), int> ();
125 test_result_of<PMS0C(const S&), int> ();
126 test_result_of<PMS0C( S*), int> ();
127 test_result_of<PMS0C(const S*), int> ();
128 test_result_of<PMS0C( S*&), int> ();
129 test_result_of<PMS0C(const S*&), int> ();
130 test_result_of<PMS0C(std::unique_ptr<S>), int> ();
131 test_no_result<PMS0C(volatile S&)>();
132 test_no_result<PMS0C(const volatile S&)>();
133
134 test_result_of<PMS1C( S, int), int*> ();
135 test_result_of<PMS1C( S&, int), int*> ();
136 test_result_of<PMS1C(const S&, int), int*> ();
137 test_result_of<PMS1C( S*, int), int*> ();
138 test_result_of<PMS1C(const S*, int), int*> ();
139 test_result_of<PMS1C( S*&, int), int*> ();
140 test_result_of<PMS1C(const S*&, int), int*> ();
141 test_result_of<PMS1C(std::unique_ptr<S>, int), int*> ();
142 test_no_result<PMS1C(volatile S&, int)>();
143 test_no_result<PMS1C(const volatile S&, int)>();
144
145 test_result_of<PMS2C( S, int, int), int&> ();
146 test_result_of<PMS2C( S&, int, int), int&> ();
147 test_result_of<PMS2C(const S&, int, int), int&> ();
148 test_result_of<PMS2C( S*, int, int), int&> ();
149 test_result_of<PMS2C(const S*, int, int), int&> ();
150 test_result_of<PMS2C( S*&, int, int), int&> ();
151 test_result_of<PMS2C(const S*&, int, int), int&> ();
152 test_result_of<PMS2C(std::unique_ptr<S>, int, int), int&> ();
153 test_no_result<PMS2C(volatile S&, int, int)>();
154 test_no_result<PMS2C(const volatile S&, int, int)>();
155
156 typedef int (S::*PMS0V)() volatile;
157 typedef int* (S::*PMS1V)(long) volatile;
158 typedef int& (S::*PMS2V)(long, int) volatile;
159 test_result_of<PMS0V( S), int> ();
160 test_result_of<PMS0V( S&), int> ();
161 test_result_of<PMS0V(volatile S&), int> ();
162 test_result_of<PMS0V( S*), int> ();
163 test_result_of<PMS0V(volatile S*), int> ();
164 test_result_of<PMS0V( S*&), int> ();
165 test_result_of<PMS0V(volatile S*&), int> ();
166 test_result_of<PMS0V(std::unique_ptr<S>), int> ();
167 test_no_result<PMS0V(const S&)>();
168 test_no_result<PMS0V(const volatile S&)>();
169
170 test_result_of<PMS1V( S, int), int*> ();
171 test_result_of<PMS1V( S&, int), int*> ();
172 test_result_of<PMS1V(volatile S&, int), int*> ();
173 test_result_of<PMS1V( S*, int), int*> ();
174 test_result_of<PMS1V(volatile S*, int), int*> ();
175 test_result_of<PMS1V( S*&, int), int*> ();
176 test_result_of<PMS1V(volatile S*&, int), int*> ();
177 test_result_of<PMS1V(std::unique_ptr<S>, int), int*> ();
178 test_no_result<PMS1V(const S&, int)>();
179 test_no_result<PMS1V(const volatile S&, int)>();
180
181 test_result_of<PMS2V( S, int, int), int&> ();
182 test_result_of<PMS2V( S&, int, int), int&> ();
183 test_result_of<PMS2V(volatile S&, int, int), int&> ();
184 test_result_of<PMS2V( S*, int, int), int&> ();
185 test_result_of<PMS2V(volatile S*, int, int), int&> ();
186 test_result_of<PMS2V( S*&, int, int), int&> ();
187 test_result_of<PMS2V(volatile S*&, int, int), int&> ();
188 test_result_of<PMS2V(std::unique_ptr<S>, int, int), int&> ();
189 test_no_result<PMS2V(const S&, int, int)>();
190 test_no_result<PMS2V(const volatile S&, int, int)>();
191
192 typedef int (S::*PMS0CV)() const volatile;
193 typedef int* (S::*PMS1CV)(long) const volatile;
194 typedef int& (S::*PMS2CV)(long, int) const volatile;
195 test_result_of<PMS0CV( S), int> ();
196 test_result_of<PMS0CV( S&), int> ();
197 test_result_of<PMS0CV(const S&), int> ();
198 test_result_of<PMS0CV(volatile S&), int> ();
199 test_result_of<PMS0CV(const volatile S&), int> ();
200 test_result_of<PMS0CV( S*), int> ();
201 test_result_of<PMS0CV(const S*), int> ();
202 test_result_of<PMS0CV(volatile S*), int> ();
203 test_result_of<PMS0CV(const volatile S*), int> ();
204 test_result_of<PMS0CV( S*&), int> ();
205 test_result_of<PMS0CV(const S*&), int> ();
206 test_result_of<PMS0CV(volatile S*&), int> ();
207 test_result_of<PMS0CV(const volatile S*&), int> ();
208 test_result_of<PMS0CV(std::unique_ptr<S>), int> ();
209
210 test_result_of<PMS1CV( S, int), int*> ();
211 test_result_of<PMS1CV( S&, int), int*> ();
212 test_result_of<PMS1CV(const S&, int), int*> ();
213 test_result_of<PMS1CV(volatile S&, int), int*> ();
214 test_result_of<PMS1CV(const volatile S&, int), int*> ();
215 test_result_of<PMS1CV( S*, int), int*> ();
216 test_result_of<PMS1CV(const S*, int), int*> ();
217 test_result_of<PMS1CV(volatile S*, int), int*> ();
218 test_result_of<PMS1CV(const volatile S*, int), int*> ();
219 test_result_of<PMS1CV( S*&, int), int*> ();
220 test_result_of<PMS1CV(const S*&, int), int*> ();
221 test_result_of<PMS1CV(volatile S*&, int), int*> ();
222 test_result_of<PMS1CV(const volatile S*&, int), int*> ();
223 test_result_of<PMS1CV(std::unique_ptr<S>, int), int*> ();
224
225 test_result_of<PMS2CV( S, int, int), int&> ();
226 test_result_of<PMS2CV( S&, int, int), int&> ();
227 test_result_of<PMS2CV(const S&, int, int), int&> ();
228 test_result_of<PMS2CV(volatile S&, int, int), int&> ();
229 test_result_of<PMS2CV(const volatile S&, int, int), int&> ();
230 test_result_of<PMS2CV( S*, int, int), int&> ();
231 test_result_of<PMS2CV(const S*, int, int), int&> ();
232 test_result_of<PMS2CV(volatile S*, int, int), int&> ();
233 test_result_of<PMS2CV(const volatile S*, int, int), int&> ();
234 test_result_of<PMS2CV( S*&, int, int), int&> ();
235 test_result_of<PMS2CV(const S*&, int, int), int&> ();
236 test_result_of<PMS2CV(volatile S*&, int, int), int&> ();
237 test_result_of<PMS2CV(const volatile S*&, int, int), int&> ();
238 test_result_of<PMS2CV(std::unique_ptr<S>, int, int), int&> ();
239 }
240 { // pointer to member data
241 typedef char S::*PMD;
242 test_result_of<PMD(S&), char &>();
243 test_result_of<PMD(S*), char &>();
244 test_result_of<PMD(S* const), char &>();
245 test_result_of<PMD(const S&), const char&> ();
246 test_result_of<PMD(const S*), const char&> ();
247 test_result_of<PMD(volatile S&), volatile char&> ();
248 test_result_of<PMD(volatile S*), volatile char&> ();
249 test_result_of<PMD(const volatile S&), const volatile char&> ();
250 test_result_of<PMD(const volatile S*), const volatile char&> ();
251 }
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000252}