1// Copyright 2021 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/core/type_name.hpp>
6#include <boost/core/lightweight_test.hpp>
7#include <boost/config.hpp>
8#include <string>
9#include <vector>
10#include <list>
11#include <deque>
12#include <set>
13#include <map>
14#include <utility>
15#include <cstddef>
16#include <iosfwd>
17
18#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
19# include <unordered_set>
20#endif
21
22#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_MAP)
23# include <unordered_map>
24#endif
25
26#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
27# include <array>
28#endif
29
30#if !defined(BOOST_NO_CXX11_HDR_TUPLE)
31# include <tuple>
32#endif
33
34#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
35# include <string_view>
36#endif
37
38//
39
40#define TEST(...) BOOST_TEST_EQ((boost::core::type_name<__VA_ARGS__>()), std::string(#__VA_ARGS__))
41
42struct A
43{
44};
45
46class B
47{
48};
49
50class C;
51
52template<class T1, class T2> struct X
53{
54};
55
56template<class T1, class T2> struct Y;
57
58enum E1
59{
60 e1
61};
62
63#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
64
65enum class E2
66{
67 e2
68};
69
70enum class E3;
71
72#endif
73
74struct Ch
75{
76};
77
78int main()
79{
80 TEST(signed char);
81 TEST(unsigned char);
82 TEST(short);
83 TEST(unsigned short);
84 TEST(int);
85 TEST(unsigned);
86 TEST(long);
87 TEST(unsigned long);
88 TEST(long long);
89 TEST(unsigned long long);
90
91#if defined(BOOST_HAS_INT128)
92 TEST(__int128);
93 TEST(unsigned __int128);
94#endif
95
96 TEST(char);
97 TEST(wchar_t);
98#if !defined(BOOST_NO_CXX11_CHAR16_T)
99 TEST(char16_t);
100#endif
101#if !defined(BOOST_NO_CXX11_CHAR16_T)
102 TEST(char32_t);
103#endif
104#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
105 TEST(char8_t);
106#endif
107#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L
108 TEST(std::byte);
109#endif
110
111 TEST(bool);
112
113 TEST(float);
114 TEST(double);
115 TEST(long double);
116
117 TEST(void);
118 TEST(void const);
119 TEST(void volatile);
120 TEST(void const volatile);
121
122 TEST(A);
123 TEST(B);
124 TEST(C);
125
126 TEST(E1);
127
128#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
129
130 TEST(E2);
131 TEST(E3);
132
133#endif
134
135 TEST(A const);
136 TEST(A volatile);
137 TEST(A const volatile);
138
139 TEST(B&);
140 TEST(B const&);
141
142 TEST(C volatile);
143 TEST(C&);
144 TEST(C const&);
145
146#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
147
148 TEST(B&&);
149 TEST(B const&&);
150
151#endif
152
153 TEST(A*);
154 TEST(B const* volatile*);
155
156 TEST(C*);
157 TEST(C const* volatile*);
158
159 TEST(void*);
160 TEST(void const* volatile*);
161
162#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
163
164 TEST(void());
165 TEST(int(float, A, B*));
166
167 TEST(void(*)());
168 TEST(void(**)());
169 TEST(void(***)());
170
171 TEST(void(* const* const*)());
172 TEST(void(* const* const&)());
173
174 TEST(void(&)());
175
176#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
177
178 TEST(void(&&)());
179
180#endif
181
182#if !defined(BOOST_MSVC) || BOOST_MSVC >= 1900
183
184 TEST(void() const);
185 TEST(void() volatile);
186 TEST(void() const volatile);
187
188#endif
189
190#if !defined(BOOST_NO_CXX11_REF_QUALIFIERS)
191
192 TEST(void() &);
193 TEST(void() const &);
194 TEST(void() volatile &);
195 TEST(void() const volatile &);
196
197 TEST(void() &&);
198 TEST(void() const &&);
199 TEST(void() volatile &&);
200 TEST(void() const volatile &&);
201
202#endif
203
204#if defined( __cpp_noexcept_function_type ) || defined( _NOEXCEPT_TYPES_SUPPORTED )
205
206 TEST(void() noexcept);
207 TEST(void() const noexcept);
208 TEST(void() volatile noexcept);
209 TEST(void() const volatile noexcept);
210
211 TEST(void() & noexcept);
212 TEST(void() const & noexcept);
213 TEST(void() volatile & noexcept);
214 TEST(void() const volatile & noexcept);
215
216 TEST(void() && noexcept);
217 TEST(void() const && noexcept);
218 TEST(void() volatile && noexcept);
219 TEST(void() const volatile && noexcept);
220
221#endif
222
223#endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
224
225 TEST(A[]);
226 TEST(A const[]);
227 TEST(A volatile[]);
228 TEST(A const volatile[]);
229
230#if !defined(BOOST_MSVC) || BOOST_MSVC >= 1700
231 TEST(A(&)[]);
232#endif
233 TEST(A const(***)[]);
234
235 TEST(B[1]);
236 TEST(B const[1]);
237 TEST(B volatile[1]);
238 TEST(B const volatile[1]);
239
240 TEST(B(&)[1]);
241 TEST(B const(***)[1]);
242
243 TEST(A[][2][3]);
244 TEST(A const[][2][3]);
245
246#if !defined(BOOST_MSVC) || BOOST_MSVC >= 1700
247 TEST(A(&)[][2][3]);
248#endif
249 TEST(A const(***)[][2][3]);
250
251 TEST(B[1][2][3]);
252 TEST(B const volatile[1][2][3]);
253
254 TEST(B(&)[1][2][3]);
255 TEST(B const volatile(***)[1][2][3]);
256
257#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || !defined(BOOST_MSVC)
258
259 TEST(int A::*);
260 TEST(int const B::*);
261
262#else
263
264 boost::core::type_name<int A::*>();
265 boost::core::type_name<int const B::*>();
266
267#endif
268
269#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
270
271 TEST(void(A::*)());
272 TEST(void(A::*)() const);
273 TEST(void(A::*)() volatile);
274 TEST(void(A::*)() const volatile);
275
276#else
277
278 boost::core::type_name<void(A::*)()>();
279 boost::core::type_name<void(A::*)() const>();
280 boost::core::type_name<void(A::*)() volatile>();
281 boost::core::type_name<void(A::*)() const volatile>();
282
283#endif
284
285#if !defined(BOOST_NO_CXX11_REF_QUALIFIERS)
286
287 TEST(void(A::*)() &);
288 TEST(void(A::*)() const &&);
289
290#endif
291
292#if defined( __cpp_noexcept_function_type ) || defined( _NOEXCEPT_TYPES_SUPPORTED )
293
294 TEST(void(A::*)() volatile & noexcept);
295 TEST(void(A::*)() const volatile && noexcept);
296
297#endif
298
299#if !defined(BOOST_NO_CXX11_NULLPTR)
300
301 TEST(std::nullptr_t);
302
303#endif
304
305 TEST(std::pair<A, B>);
306 TEST(std::pair<A const*, B*> volatile&);
307
308 TEST(std::pair<C, C>);
309
310 TEST(std::pair<void, void>);
311 TEST(std::pair<std::pair<void, void>, void>);
312
313#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 160000
314// std::char_traits<Ch> is deprecated for non-char types
315#else
316 TEST(std::basic_string<Ch>);
317#endif
318
319 TEST(std::string);
320 TEST(std::wstring);
321
322#if BOOST_CXX_VERSION >= 201100L
323
324 TEST(std::u16string);
325 TEST(std::u32string);
326
327#endif
328
329#if BOOST_CXX_VERSION >= 202000L
330
331 TEST(std::u8string);
332
333#endif
334
335 TEST(X<A, B>);
336 TEST(X<A const&, B&> volatile&);
337
338 TEST(X<C, C>);
339
340 TEST(Y<A, B>);
341 TEST(Y<C, C>);
342
343 TEST(X<std::pair<void, void>, void>);
344
345 TEST(std::vector<int>);
346 TEST(std::vector<A>);
347 TEST(std::vector<std::string>);
348
349 TEST(std::list<int>);
350 TEST(std::list<B>);
351 TEST(std::list<std::wstring>);
352
353 TEST(std::deque<int>);
354 TEST(std::deque<A>);
355 TEST(std::deque<std::string>);
356
357 TEST(std::set<int>);
358 TEST(std::set<B>);
359 TEST(std::set<std::string>);
360
361 TEST(std::map<int, A>);
362 TEST(std::map<std::string, B>);
363 TEST(std::map<std::wstring, std::vector<std::string> const*> const&);
364
365#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
366
367 TEST(std::unordered_set<int>);
368 TEST(std::unordered_set<std::string>);
369
370#endif
371
372#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_MAP)
373
374 TEST(std::unordered_map<int, A>);
375 TEST(std::unordered_map<std::string, B>);
376 TEST(std::unordered_map<std::wstring, std::set<std::string>*>);
377
378#endif
379
380#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
381
382 TEST(std::array<std::string, 7>);
383 TEST(std::array<std::wstring const*, 0> const&);
384
385#endif
386
387#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && ( !defined(BOOST_MSVC) || BOOST_MSVC >= 1700 )
388
389 TEST(std::tuple<>);
390 TEST(std::tuple<int>);
391 TEST(std::tuple<int, float>);
392 TEST(std::tuple<int, float, std::string>);
393
394 TEST(std::tuple<void>);
395 TEST(std::tuple<void, void>);
396 TEST(std::tuple<void, void, void>);
397
398 TEST(std::tuple<std::tuple<void, void>, void>);
399
400 TEST(X<std::tuple<void>, void>);
401
402#endif
403
404 TEST(std::ostream);
405 TEST(std::basic_ostream<wchar_t>);
406
407#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
408
409#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 160000
410// std::char_traits<Ch> is deprecated for non-char types
411#else
412 TEST(std::basic_string_view<Ch>);
413#endif
414
415 TEST(std::string_view);
416 TEST(std::wstring_view);
417
418#if BOOST_CXX_VERSION >= 201100L
419
420 TEST(std::u16string_view);
421 TEST(std::u32string_view);
422
423#endif
424
425#if BOOST_CXX_VERSION >= 202000L
426
427 TEST(std::u8string_view);
428
429#endif
430
431#endif
432
433 return boost::report_errors();
434}
435

source code of boost/libs/core/test/type_name_test.cpp