1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // UNSUPPORTED: c++98, c++03
11 //
12 // <functional>
13 //
14 // result_of<Fn(ArgTypes...)>
15
16 #include <type_traits>
17 #include <memory>
18 #include <utility>
19 #include "test_macros.h"
20
21 struct wat
22 {
operator *wat23 wat& operator*() { return *this; }
24 void foo();
25 };
26
27 struct F {};
28 struct FD : public F {};
29
30 #if TEST_STD_VER > 14
31 template <typename T, typename U>
32 struct test_invoke_result;
33
34 template <typename Fn, typename ...Args, typename Ret>
35 struct test_invoke_result<Fn(Args...), Ret>
36 {
calltest_invoke_result37 static void call()
38 {
39 static_assert(std::is_invocable<Fn, Args...>::value, "");
40 static_assert(std::is_invocable_r<Ret, Fn, Args...>::value, "");
41 static_assert((std::is_same<typename std::invoke_result<Fn, Args...>::type, Ret>::value), "");
42 static_assert((std::is_same<std::invoke_result_t<Fn, Args...>, Ret>::value), "");
43 }
44 };
45 #endif
46
47 template <class T, class U>
test_result_of_imp()48 void test_result_of_imp()
49 {
50 static_assert((std::is_same<typename std::result_of<T>::type, U>::value), "");
51 #if TEST_STD_VER > 11
52 static_assert((std::is_same<std::result_of_t<T>, U>::value), "");
53 #endif
54 #if TEST_STD_VER > 14
55 test_invoke_result<T, U>::call();
56 #endif
57 }
58
main()59 int main()
60 {
61 {
62 typedef char F::*PMD;
63 test_result_of_imp<PMD(F &), char &>();
64 test_result_of_imp<PMD(F const &), char const &>();
65 test_result_of_imp<PMD(F volatile &), char volatile &>();
66 test_result_of_imp<PMD(F const volatile &), char const volatile &>();
67
68 test_result_of_imp<PMD(F &&), char &&>();
69 test_result_of_imp<PMD(F const &&), char const &&>();
70 test_result_of_imp<PMD(F volatile &&), char volatile &&>();
71 test_result_of_imp<PMD(F const volatile &&), char const volatile &&>();
72
73 test_result_of_imp<PMD(F ), char &&>();
74 test_result_of_imp<PMD(F const ), char &&>();
75 test_result_of_imp<PMD(F volatile ), char &&>();
76 test_result_of_imp<PMD(F const volatile ), char &&>();
77
78 test_result_of_imp<PMD(FD &), char &>();
79 test_result_of_imp<PMD(FD const &), char const &>();
80 test_result_of_imp<PMD(FD volatile &), char volatile &>();
81 test_result_of_imp<PMD(FD const volatile &), char const volatile &>();
82
83 test_result_of_imp<PMD(FD &&), char &&>();
84 test_result_of_imp<PMD(FD const &&), char const &&>();
85 test_result_of_imp<PMD(FD volatile &&), char volatile &&>();
86 test_result_of_imp<PMD(FD const volatile &&), char const volatile &&>();
87
88 test_result_of_imp<PMD(FD ), char &&>();
89 test_result_of_imp<PMD(FD const ), char &&>();
90 test_result_of_imp<PMD(FD volatile ), char &&>();
91 test_result_of_imp<PMD(FD const volatile ), char &&>();
92
93 test_result_of_imp<PMD(std::unique_ptr<F>), char &>();
94 test_result_of_imp<PMD(std::unique_ptr<F const>), const char &>();
95 test_result_of_imp<PMD(std::unique_ptr<FD>), char &>();
96 test_result_of_imp<PMD(std::unique_ptr<FD const>), const char &>();
97
98 test_result_of_imp<PMD(std::reference_wrapper<F>), char &>();
99 test_result_of_imp<PMD(std::reference_wrapper<F const>), const char &>();
100 test_result_of_imp<PMD(std::reference_wrapper<FD>), char &>();
101 test_result_of_imp<PMD(std::reference_wrapper<FD const>), const char &>();
102 }
103 {
104 test_result_of_imp<int (F::* (F &)) () &, int> ();
105 test_result_of_imp<int (F::* (F &)) () const &, int> ();
106 test_result_of_imp<int (F::* (F &)) () volatile &, int> ();
107 test_result_of_imp<int (F::* (F &)) () const volatile &, int> ();
108 test_result_of_imp<int (F::* (F const &)) () const &, int> ();
109 test_result_of_imp<int (F::* (F const &)) () const volatile &, int> ();
110 test_result_of_imp<int (F::* (F volatile &)) () volatile &, int> ();
111 test_result_of_imp<int (F::* (F volatile &)) () const volatile &, int> ();
112 test_result_of_imp<int (F::* (F const volatile &)) () const volatile &, int> ();
113
114 test_result_of_imp<int (F::* (F &&)) () &&, int> ();
115 test_result_of_imp<int (F::* (F &&)) () const &&, int> ();
116 test_result_of_imp<int (F::* (F &&)) () volatile &&, int> ();
117 test_result_of_imp<int (F::* (F &&)) () const volatile &&, int> ();
118 test_result_of_imp<int (F::* (F const &&)) () const &&, int> ();
119 test_result_of_imp<int (F::* (F const &&)) () const volatile &&, int> ();
120 test_result_of_imp<int (F::* (F volatile &&)) () volatile &&, int> ();
121 test_result_of_imp<int (F::* (F volatile &&)) () const volatile &&, int> ();
122 test_result_of_imp<int (F::* (F const volatile &&)) () const volatile &&, int> ();
123
124 test_result_of_imp<int (F::* (F )) () &&, int> ();
125 test_result_of_imp<int (F::* (F )) () const &&, int> ();
126 test_result_of_imp<int (F::* (F )) () volatile &&, int> ();
127 test_result_of_imp<int (F::* (F )) () const volatile &&, int> ();
128 test_result_of_imp<int (F::* (F const )) () const &&, int> ();
129 test_result_of_imp<int (F::* (F const )) () const volatile &&, int> ();
130 test_result_of_imp<int (F::* (F volatile )) () volatile &&, int> ();
131 test_result_of_imp<int (F::* (F volatile )) () const volatile &&, int> ();
132 test_result_of_imp<int (F::* (F const volatile )) () const volatile &&, int> ();
133 }
134 {
135 test_result_of_imp<int (F::* (FD &)) () &, int> ();
136 test_result_of_imp<int (F::* (FD &)) () const &, int> ();
137 test_result_of_imp<int (F::* (FD &)) () volatile &, int> ();
138 test_result_of_imp<int (F::* (FD &)) () const volatile &, int> ();
139 test_result_of_imp<int (F::* (FD const &)) () const &, int> ();
140 test_result_of_imp<int (F::* (FD const &)) () const volatile &, int> ();
141 test_result_of_imp<int (F::* (FD volatile &)) () volatile &, int> ();
142 test_result_of_imp<int (F::* (FD volatile &)) () const volatile &, int> ();
143 test_result_of_imp<int (F::* (FD const volatile &)) () const volatile &, int> ();
144
145 test_result_of_imp<int (F::* (FD &&)) () &&, int> ();
146 test_result_of_imp<int (F::* (FD &&)) () const &&, int> ();
147 test_result_of_imp<int (F::* (FD &&)) () volatile &&, int> ();
148 test_result_of_imp<int (F::* (FD &&)) () const volatile &&, int> ();
149 test_result_of_imp<int (F::* (FD const &&)) () const &&, int> ();
150 test_result_of_imp<int (F::* (FD const &&)) () const volatile &&, int> ();
151 test_result_of_imp<int (F::* (FD volatile &&)) () volatile &&, int> ();
152 test_result_of_imp<int (F::* (FD volatile &&)) () const volatile &&, int> ();
153 test_result_of_imp<int (F::* (FD const volatile &&)) () const volatile &&, int> ();
154
155 test_result_of_imp<int (F::* (FD )) () &&, int> ();
156 test_result_of_imp<int (F::* (FD )) () const &&, int> ();
157 test_result_of_imp<int (F::* (FD )) () volatile &&, int> ();
158 test_result_of_imp<int (F::* (FD )) () const volatile &&, int> ();
159 test_result_of_imp<int (F::* (FD const )) () const &&, int> ();
160 test_result_of_imp<int (F::* (FD const )) () const volatile &&, int> ();
161 test_result_of_imp<int (F::* (FD volatile )) () volatile &&, int> ();
162 test_result_of_imp<int (F::* (FD volatile )) () const volatile &&, int> ();
163 test_result_of_imp<int (F::* (FD const volatile )) () const volatile &&, int> ();
164 }
165 {
166 test_result_of_imp<int (F::* (std::reference_wrapper<F>)) (), int>();
167 test_result_of_imp<int (F::* (std::reference_wrapper<const F>)) () const, int>();
168 test_result_of_imp<int (F::* (std::unique_ptr<F> )) (), int>();
169 test_result_of_imp<int (F::* (std::unique_ptr<const F> )) () const, int>();
170 }
171 test_result_of_imp<decltype(&wat::foo)(wat), void>();
172 }
173