1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/FunctionTypeTraits.h"
11 using mozilla::FunctionTypeTraits
;
15 int f1(char) { return 0; }
17 #ifdef NS_HAVE_STDCALL
18 void NS_STDCALL
f0s() {}
20 int NS_STDCALL
f1s(char) { return 0; }
21 #endif // NS_HAVE_STDCALL
26 int f1(char) { return 0; }
27 int f1c(char) const { return 0; }
28 #ifdef NS_HAVE_STDCALL
29 void NS_STDCALL
f0s() {}
30 void NS_STDCALL
f0cs() const {}
31 int NS_STDCALL
f1s(char) { return 0; }
32 int NS_STDCALL
f1cs(char) const { return 0; }
33 #endif // NS_HAVE_STDCALL
37 std::is_same
<typename FunctionTypeTraits
<decltype(f0
)>::ReturnType
,
40 static_assert(FunctionTypeTraits
<decltype(f0
)>::arity
== 0,
41 "f0 takes no parameters");
44 typename FunctionTypeTraits
<decltype(f0
)>::template ParameterType
<0>,
46 "f0 has no first parameter");
49 std::is_same
<typename FunctionTypeTraits
<decltype(&S::f0
)>::ReturnType
,
51 "S::f0 returns void");
52 static_assert(FunctionTypeTraits
<decltype(&S::f0
)>::arity
== 0,
53 "S::f0 takes no parameters");
54 static_assert(std::is_same
<typename FunctionTypeTraits
<
55 decltype(&S::f0
)>::template ParameterType
<0>,
57 "S::f0 has no first parameter");
60 std::is_same
<typename FunctionTypeTraits
<decltype(&S::f0c
)>::ReturnType
,
62 "S::f0c returns void");
63 static_assert(FunctionTypeTraits
<decltype(&S::f0c
)>::arity
== 0,
64 "S::f0c takes no parameters");
65 static_assert(std::is_same
<typename FunctionTypeTraits
<
66 decltype(&S::f0c
)>::template ParameterType
<0>,
68 "S::f0c has no first parameter");
71 std::is_same
<typename FunctionTypeTraits
<decltype(f1
)>::ReturnType
,
74 static_assert(FunctionTypeTraits
<decltype(f1
)>::arity
== 1,
75 "f1 takes one parameter");
78 typename FunctionTypeTraits
<decltype(f1
)>::template ParameterType
<0>,
83 std::is_same
<typename FunctionTypeTraits
<decltype(&S::f1
)>::ReturnType
,
86 static_assert(FunctionTypeTraits
<decltype(&S::f1
)>::arity
== 1,
87 "S::f1 takes one parameter");
88 static_assert(std::is_same
<typename FunctionTypeTraits
<
89 decltype(&S::f1
)>::template ParameterType
<0>,
91 "S::f1 takes a char");
94 std::is_same
<typename FunctionTypeTraits
<decltype(&S::f1c
)>::ReturnType
,
96 "S::f1c returns int");
97 static_assert(FunctionTypeTraits
<decltype(&S::f1c
)>::arity
== 1,
98 "S::f1c takes one parameter");
99 static_assert(std::is_same
<typename FunctionTypeTraits
<
100 decltype(&S::f1c
)>::template ParameterType
<0>,
102 "S::f1c takes a char");
104 #ifdef NS_HAVE_STDCALL
106 std::is_same
<typename FunctionTypeTraits
<decltype(f0s
)>::ReturnType
,
109 static_assert(FunctionTypeTraits
<decltype(f0s
)>::arity
== 0,
110 "f0s takes no parameters");
113 typename FunctionTypeTraits
<decltype(f0s
)>::template ParameterType
<0>,
115 "f0s has no first parameter");
118 std::is_same
<typename FunctionTypeTraits
<decltype(&S::f0s
)>::ReturnType
,
120 "S::f0s returns void");
121 static_assert(FunctionTypeTraits
<decltype(&S::f0s
)>::arity
== 0,
122 "S::f0s takes no parameters");
123 static_assert(std::is_same
<typename FunctionTypeTraits
<
124 decltype(&S::f0s
)>::template ParameterType
<0>,
126 "S::f0s has no first parameter");
129 std::is_same
<typename FunctionTypeTraits
<decltype(&S::f0cs
)>::ReturnType
,
131 "S::f0cs returns void");
132 static_assert(FunctionTypeTraits
<decltype(&S::f0cs
)>::arity
== 0,
133 "S::f0cs takes no parameters");
134 static_assert(std::is_same
<typename FunctionTypeTraits
<
135 decltype(&S::f0cs
)>::template ParameterType
<0>,
137 "S::f0cs has no first parameter");
140 std::is_same
<typename FunctionTypeTraits
<decltype(f1s
)>::ReturnType
,
143 static_assert(FunctionTypeTraits
<decltype(f1s
)>::arity
== 1,
144 "f1s takes one parameter");
147 typename FunctionTypeTraits
<decltype(f1s
)>::template ParameterType
<0>,
152 std::is_same
<typename FunctionTypeTraits
<decltype(&S::f1s
)>::ReturnType
,
154 "S::f1s returns int");
155 static_assert(FunctionTypeTraits
<decltype(&S::f1s
)>::arity
== 1,
156 "S::f1s takes one parameter");
157 static_assert(std::is_same
<typename FunctionTypeTraits
<
158 decltype(&S::f1s
)>::template ParameterType
<0>,
160 "S::f1s takes a char");
163 std::is_same
<typename FunctionTypeTraits
<decltype(&S::f1cs
)>::ReturnType
,
165 "S::f1cs returns int");
166 static_assert(FunctionTypeTraits
<decltype(&S::f1cs
)>::arity
== 1,
167 "S::f1cs takes one parameter");
168 static_assert(std::is_same
<typename FunctionTypeTraits
<
169 decltype(&S::f1cs
)>::template ParameterType
<0>,
171 "S::f1cs takes a char");
172 #endif // NS_HAVE_STDCALL
174 template <typename F
>
175 void TestVoidVoid(F
&&) {
177 std::is_same
<typename FunctionTypeTraits
<F
>::ReturnType
, void>::value
,
178 "Should return void");
179 static_assert(FunctionTypeTraits
<F
>::arity
== 0, "Should take no parameters");
181 std::is_same
<typename FunctionTypeTraits
<F
>::template ParameterType
<0>,
183 "Should have no first parameter");
186 template <typename F
>
187 void TestIntChar(F
&&) {
189 std::is_same
<typename FunctionTypeTraits
<F
>::ReturnType
, int>::value
,
190 "Should return int");
191 static_assert(FunctionTypeTraits
<F
>::arity
== 1, "Should take one parameter");
193 std::is_same
<typename FunctionTypeTraits
<F
>::template ParameterType
<0>,
195 "Should take a char");
201 TestVoidVoid(&S::f0
);
202 TestVoidVoid(&S::f0c
);
203 TestVoidVoid([]() {});
204 std::function
<void()> ff0
= f0
;
210 TestIntChar(&S::f1c
);
211 TestIntChar([](char) { return 0; });
212 std::function
<int(char)> ff1
= f1
;
215 #ifdef NS_HAVE_STDCALL
218 TestVoidVoid(&S::f0s
);
219 TestVoidVoid(&S::f0cs
);
220 std::function
<void()> ff0s
= f0s
;
225 TestIntChar(&S::f1s
);
226 TestIntChar(&S::f1cs
);
227 std::function
<int(char)> ff1s
= f1s
;
229 #endif // NS_HAVE_STDCALL