iutest  1.17.1.0
iutest_stdlib.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_STDLIB_HPP_54D4BEEE_7B6B_4AF4_B1F6_138560480D55_
16 #define INCG_IRIS_IUTEST_STDLIB_HPP_54D4BEEE_7B6B_4AF4_B1F6_138560480D55_
17 
18 //======================================================================
19 // include
20 #define __STDC_FORMAT_MACROS 1
21 #include <inttypes.h>
22 
23 #if defined(IUTEST_USE_GTEST) && defined(__STRICT_ANSI__)
24 # undef __STRICT_ANSI__
25 # include <string.h>
26 # include <stdlib.h>
27 # include <cstdio>
28 # define __STRICT_ANSI__
29 #endif
30 #if !defined(_MSC_VER)
31 # include <stdint.h>
32 #endif
33 #include <cstdlib>
34 #include <cstddef>
35 #include <limits>
36 
37 // <version> header
38 #if defined(__has_include)
39 # if __has_include(<version>)
40 # define IUTEST_HAS_CXX_HDR_VERSION 1
41 # endif
42 #endif
43 
44 #if !defined(IUTEST_HAS_CXX_HDR_VERSION)
45 # define IUTEST_HAS_CXX_HDR_VERSION 0
46 #endif
47 
48 #if IUTEST_HAS_CXX_HDR_VERSION
49 #include <version>
50 #endif
51 
52 //======================================================================
53 // define
54 #if defined(__GLIBCPP__) || defined(__GLIBCXX__)
55 
56 // libstdc++
57 #if defined(__clang__)
58 # if __has_include(<experimental/memory_resource>)
59 # define IUTEST_LIBSTDCXX_VERSION 60100
60 # elif __has_include(<experimental/any>)
61 # define IUTEST_LIBSTDCXX_VERSION 50100
62 # elif __has_include(<shared_mutex>)
63 # define IUTEST_LIBSTDCXX_VERSION 40900
64 # elif __has_include(<ext/cmath>)
65 # define IUTEST_LIBSTDCXX_VERSION 40800
66 # elif __has_include(<scoped_allocator>)
67 # define IUTEST_LIBSTDCXX_VERSION 40700
68 # elif __has_include(<typeindex>)
69 # define IUTEST_LIBSTDCXX_VERSION 40600
70 # elif __has_include(<future>)
71 # define IUTEST_LIBSTDCXX_VERSION 40500
72 # elif __has_include(<ratio>)
73 # define IUTEST_LIBSTDCXX_VERSION 40400
74 # elif __has_include(<array>)
75 # define IUTEST_LIBSTDCXX_VERSION 40300
76 # endif
77 #elif defined(__GNUC__)
78 # define IUTEST_LIBSTDCXX_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
79 #endif
80 
81 #if IUTEST_HAS_CXX11
82 # if IUTEST_LIBSTDCXX_VERSION >= 60100
83 # if !defined(IUTEST_HAS_STD_INVOKE) && IUTEST_HAS_CXX1Z
84 # define IUTEST_HAS_STD_INVOKE 1
85 # endif
86 # endif
87 # if IUTEST_LIBSTDCXX_VERSION >= 50100
88 # if !defined(IUTEST_HAS_CXX_HDR_CODECVT)
89 # define IUTEST_HAS_CXX_HDR_CODECVT 1
90 # endif
91 # endif
92 # if IUTEST_LIBSTDCXX_VERSION >= 40900
93 # if !defined(IUTEST_HAS_CXX_HDR_REGEX)
94 # define IUTEST_HAS_CXX_HDR_REGEX 1
95 # endif
96 # endif
97 # if IUTEST_LIBSTDCXX_VERSION >= 40700
98 # if !defined(IUTEST_HAS_STD_EMPLACE)
99 # define IUTEST_HAS_STD_EMPLACE 1
100 # endif
101 # if !defined(IUTEST_HAS_CXX_HDR_CHRONO)
102 # define IUTEST_HAS_CXX_HDR_CHRONO 1
103 # endif
104 # endif
105 # if IUTEST_LIBSTDCXX_VERSION >= 40600
106 # if !defined(IUTEST_HAS_STD_BEGIN_END)
107 # define IUTEST_HAS_STD_BEGIN_END 1
108 # endif
109 # endif
110 # if IUTEST_LIBSTDCXX_VERSION >= 40500
111 # if !defined(IUTEST_HAS_STD_DECLVAL)
112 # define IUTEST_HAS_STD_DECLVAL 1
113 # endif
114 # if !defined(IUTEST_HAS_CXX_HDR_RANDOM)
115 # define IUTEST_HAS_CXX_HDR_RANDOM 1
116 # endif
117 # if !defined(IUTEST_HAS_CXX_HDR_CSTDINT)
118 # define IUTEST_HAS_CXX_HDR_CSTDINT 1
119 # endif
120 # endif
121 # if IUTEST_LIBSTDCXX_VERSION >= 40300
122 # if !defined(IUTEST_HAS_CXX_HDR_ARRAY)
123 # define IUTEST_HAS_CXX_HDR_ARRAY 1
124 # endif
125 # if !defined(IUTEST_HAS_STD_TUPLE)
126 # define IUTEST_HAS_STD_TUPLE 1
127 # endif
128 # endif
129 # if defined(_GLIBCXX_HAVE_QUICK_EXIT) && defined(_GLIBCXX_HAVE_AT_QUICK_EXIT)
130 # if !defined(IUTEST_HAS_STD_QUICK_EXIT)
131 # define IUTEST_HAS_STD_QUICK_EXIT 1
132 # endif
133 # endif
134 # if defined(__has_include)
135 # if !defined(IUTEST_HAS_CXX_HDR_CUCHAR) && __has_include( <cuchar> )
136 # if defined(_GLIBCXX_USE_C11_UCHAR_CXX11) && _GLIBCXX_USE_C11_UCHAR_CXX11
137 # define IUTEST_HAS_CXX_HDR_CUCHAR 1
138 # endif
139 # endif
140 # endif
141 #endif
142 
143 #if !defined(IUTEST_HAS_STD_TUPLE)
144 # if (!defined(__CUDACC__) && !defined(__ARMCC_VERSION) && (IUTEST_LIBSTDCXX_VERSION >= 40000))
145 # if !defined(IUTEST_HAS_TR1_TUPLE)
146 # define IUTEST_HAS_TR1_TUPLE 1
147 # endif
148 # endif
149 #endif
150 
151 #if !defined(IUTEST_HAS_HDR_CXXABI)
152 # if defined(__has_include)
153 # if __has_include( <cxxabi.h> )
154 # define IUTEST_HAS_HDR_CXXABI 1
155 # endif
156 # else
157 # define IUTEST_HAS_HDR_CXXABI 1
158 # endif
159 #endif
160 
161 #if defined(__GNUC__) && !defined(__clang__)
162 // GCC 8.x requires linking with -lstdc++fs. (iutest not support)
163 # if (__GNUC__ < 9)
164 # define IUTEST_HAS_CXX_HDR_FILESYSTEM 0
165 # endif
166 #endif
167 
168 #elif defined(_LIBCPP_VERSION)
169 
170 // libc++
171 #if IUTEST_HAS_CXX11
172 # if !defined(IUTEST_HAS_STD_BEGIN_END)
173 # define IUTEST_HAS_STD_BEGIN_END 1
174 # endif
175 # if !defined(IUTEST_HAS_STD_DECLVAL)
176 # define IUTEST_HAS_STD_DECLVAL 1
177 # endif
178 # if !defined(IUTEST_HAS_STD_EMPLACE)
179 # define IUTEST_HAS_STD_EMPLACE 1
180 # endif
181 # if !defined(IUTEST_HAS_CXX_HDR_CHRONO)
182 # define IUTEST_HAS_CXX_HDR_CHRONO 1
183 # endif
184 # if !defined(IUTEST_HAS_CXX_HDR_REGEX)
185 # define IUTEST_HAS_CXX_HDR_REGEX 1
186 # endif
187 # if !defined(IUTEST_HAS_CXX_HDR_RANDOM)
188 # define IUTEST_HAS_CXX_HDR_RANDOM 1
189 # endif
190 # if !defined(IUTEST_HAS_CXX_HDR_CODECVT)
191 # define IUTEST_HAS_CXX_HDR_CODECVT 1
192 # endif
193 # if !defined(IUTEST_HAS_CXX_HDR_CSTDINT)
194 # define IUTEST_HAS_CXX_HDR_CSTDINT 1
195 # endif
196 # if !defined(IUTEST_HAS_CXX_HDR_ARRAY)
197 # define IUTEST_HAS_CXX_HDR_ARRAY 1
198 # endif
199 # if !defined(IUTEST_HAS_STD_QUICK_EXIT) && defined(_LIBCPP_HAS_QUICK_EXIT)
200 # define IUTEST_HAS_STD_QUICK_EXIT 1
201 # endif
202 # if defined(__has_include)
203 # if !defined(IUTEST_HAS_CXX_HDR_CUCHAR) && __has_include( <cuchar> )
204 # define IUTEST_HAS_CXX_HDR_CUCHAR 1
205 # endif
206 # if !defined(IUTEST_HAS_STD_TUPLE) && __has_include( <tuple> )
207 # define IUTEST_HAS_STD_TUPLE 1
208 # endif
209 # endif
210 #endif
211 
212 #if _LIBCPP_VERSION < 9000
213 # define IUTEST_HAS_CXX_HDR_FILESYSTEM 0
214 #endif
215 #if _LIBCPP_VERSION >= 3700
216 # if !defined(IUTEST_HAS_STD_INVOKE) && IUTEST_HAS_CXX1Z
217 # define IUTEST_HAS_STD_INVOKE 1
218 # endif
219 #endif
220 #if _LIBCPP_VERSION >= 1001
221 # if !defined(IUTEST_HAS_STD_BEGIN_END)
222 # define IUTEST_HAS_STD_BEGIN_END 1
223 # endif
224 #endif
225 
226 #if defined(__has_include)
227 # if !defined(IUTEST_HAS_STD_TUPLE) && !defined(IUTEST_HAS_TR1_TUPLE) && __has_include( <tr1/tuple> )
228 # define IUTEST_HAS_TR1_TUPLE 1
229 # endif
230 # if !defined(IUTEST_HAS_HDR_CXXABI) && __has_include( <cxxabi.h> )
231 # define IUTEST_HAS_HDR_CXXABI 1
232 # endif
233 #endif
234 
235 #elif defined(_MSC_VER) && defined(_MSC_FULL_VER)
236 
237 // Visual C++
238 
239 #if _MSC_VER >= 1600
240 # if !defined(IUTEST_HAS_CXX_HDR_ARRAY)
241 # define IUTEST_HAS_CXX_HDR_ARRAY 1
242 # endif
243 #endif
244 
245 #if _MSC_VER >= 1700
246 # if !defined(IUTEST_HAS_STD_BEGIN_END)
247 # define IUTEST_HAS_STD_BEGIN_END 1
248 # endif
249 # if !defined(IUTEST_HAS_STD_DECLVAL)
250 # define IUTEST_HAS_STD_DECLVAL IUTEST_HAS_DECLTYPE
251 # endif
252 # if !defined(IUTEST_HAS_STD_EMPLACE)
253 # define IUTEST_HAS_STD_EMPLACE 1
254 # endif
255 # if !defined(IUTEST_HAS_CXX_HDR_REGEX)
256 # define IUTEST_HAS_CXX_HDR_REGEX 1
257 # endif
258 # if !defined(IUTEST_HAS_CXX_HDR_RANDOM)
259 # define IUTEST_HAS_CXX_HDR_RANDOM 1
260 # endif
261 # if !defined(IUTEST_HAS_CXX_HDR_CODECVT)
262 # define IUTEST_HAS_CXX_HDR_CODECVT 1
263 # endif
264 # if !defined(IUTEST_HAS_CXX_HDR_CSTDINT)
265 # define IUTEST_HAS_CXX_HDR_CSTDINT 1
266 # endif
267 # if !defined(IUTEST_HAS_CXX_HDR_CHRONO) && _MSC_FULL_VER != 190023725
268 # define IUTEST_HAS_CXX_HDR_CHRONO 1
269 # endif
270 #endif
271 
272 #if _MSC_VER >= 1900
273 # if !defined(IUTEST_HAS_STD_QUICK_EXIT)
274 # define IUTEST_HAS_STD_QUICK_EXIT 1
275 # endif
276 # if !defined(IUTEST_HAS_CXX_HDR_CUCHAR)
277 # define IUTEST_HAS_CXX_HDR_CUCHAR 1
278 # endif
279 #endif
280 
281 #if _MSC_VER >= 1916
282 # if !defined(IUTEST_HAS_CXX_HDR_CHARCONV) && IUTEST_HAS_CXX17
283 # define IUTEST_HAS_CXX_HDR_CHARCONV 1
284 # endif
285 #endif
286 
287 // tuple
288 #if (_MSC_VER > 1700) || (_MSC_VER == 1700 && _VARIADIC_MAX >= 9)
289 # if !defined(IUTEST_HAS_STD_TUPLE)
290 # define IUTEST_HAS_STD_TUPLE 1
291 # endif
292 #elif (_MSC_VER >= 1500) && (_MSC_VER < 1700) && (_MSC_FULL_VER > 150021022)
293 # if !defined(IUTEST_HAS_TR1_TUPLE)
294 # define IUTEST_HAS_TR1_TUPLE 1
295 # endif
296 #endif
297 
298 #elif defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
299 
300 // stlport
301 
302 #endif
303 
304 #if IUTEST_HAS_CXX1Z
305 
306 // c++1z feature
307 
308 #if defined(__has_include)
309 
310 #if !defined(IUTEST_HAS_CXX_HDR_ANY)
311 # if __has_include(<any>)
312 # define IUTEST_HAS_CXX_HDR_ANY 1
313 # endif
314 #endif
315 
316 #if !defined(IUTEST_HAS_CXX_HDR_CHARCONV)
317 # if __has_include(<charconv>)
318 # define IUTEST_HAS_CXX_HDR_CHARCONV 1
319 # endif
320 #endif
321 
322 // apple(xcode) clang
323 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
324 # if __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
325 # define IUTEST_HAS_CXX_HDR_FILESYSTEM 0
326 # endif
327 #endif
328 
329 #if !defined(IUTEST_HAS_CXX_HDR_FILESYSTEM)
330 # if __has_include(<filesystem>)
331 # define IUTEST_HAS_CXX_HDR_FILESYSTEM 1
332 # endif
333 #endif
334 
335 #if !defined(IUTEST_HAS_CXX_HDR_OPTIONAL)
336 # if __has_include(<optional>)
337 # define IUTEST_HAS_CXX_HDR_OPTIONAL 1
338 # endif
339 #endif
340 
341 #if !defined(IUTEST_HAS_CXX_HDR_STRING_VIEW)
342 # if __has_include(<string_view>)
343 # define IUTEST_HAS_CXX_HDR_STRING_VIEW 1
344 # endif
345 #endif
346 
347 #endif
348 
349 #endif
350 
351 #if IUTEST_HAS_CXX17
352 
353 // c++17 feature
354 
355 #if !defined(IUTEST_HAS_CXX_HDR_VARIANT)
356 # if IUTEST_HAS_VARIADIC_TEMPLATES && defined(__has_include)
357 # if defined(__clang__) && (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 6))
358 # define IUTEST_HAS_CXX_HDR_VARIANT 0 // clang 3.5 + variant is not worked
359 # elif __has_include(<variant>)
360 # define IUTEST_HAS_CXX_HDR_VARIANT 1
361 # endif
362 # endif
363 #endif
364 
365 #if defined(IUTEST_HAS_CXX_HDR_CODECVT) && IUTEST_HAS_CXX_HDR_CODECVT
366 // IUTEST_PRAGMA_MESSAGE("iutest use codecvt, but codecvt was deprecated. If you do not want to use this, define IUTEST_HAS_CXX_HDR_CODECVT 0")
367 #endif
368 
369 #endif
370 
371 #if defined(__has_include)
372 # if defined(IUTEST_HAS_CXX_HDR_CODECVT) && IUTEST_HAS_CXX_HDR_CODECVT
373 # if !__has_include( <codecvt> )
374 # undef IUTEST_HAS_CXX_HDR_CODECVT
375 # endif
376 # endif
377 #endif
378 
379 // defaults for include
381 #if !defined(IUTEST_HAS_CXX_HDR_ANY)
382 # define IUTEST_HAS_CXX_HDR_ANY 0
383 #endif
384 #if !defined(IUTEST_HAS_CXX_HDR_ARRAY)
386 # define IUTEST_HAS_CXX_HDR_ARRAY 0
387 #endif
388 #if !defined(IUTEST_HAS_CXX_HDR_CHARCONV)
390 # define IUTEST_HAS_CXX_HDR_CHARCONV 0
391 #endif
392 #if !defined(IUTEST_HAS_CXX_HDR_CHRONO)
394 # define IUTEST_HAS_CXX_HDR_CHRONO 0
395 #endif
396 
401 #if !defined(IUTEST_HAS_CXX_HDR_CODECVT)
402 # define IUTEST_HAS_CXX_HDR_CODECVT 0
403 #endif
404 #if !defined(IUTEST_HAS_CXX_HDR_CSTDINT)
406 # define IUTEST_HAS_CXX_HDR_CSTDINT 0
407 #endif
408 #if !defined(IUTEST_HAS_CXX_HDR_CUCHAR)
410 # define IUTEST_HAS_CXX_HDR_CUCHAR 0
411 #endif
412 #if !defined(IUTEST_HAS_CXX_HDR_FILESYSTEM)
414 # define IUTEST_HAS_CXX_HDR_FILESYSTEM 0
415 #endif
416 #if !defined(IUTEST_HAS_CXX_HDR_OPTIONAL)
418 # define IUTEST_HAS_CXX_HDR_OPTIONAL 0
419 #endif
420 #if !defined(IUTEST_HAS_CXX_HDR_RANDOM)
422 # define IUTEST_HAS_CXX_HDR_RANDOM 0
423 #endif
424 #if !defined(IUTEST_HAS_CXX_HDR_REGEX)
426 # define IUTEST_HAS_CXX_HDR_REGEX 0
427 #endif
428 #if !defined(IUTEST_HAS_CXX_HDR_STRING_VIEW)
430 # define IUTEST_HAS_CXX_HDR_STRING_VIEW 0
431 #endif
432 #if !defined(IUTEST_HAS_CXX_HDR_VARIANT)
434 # define IUTEST_HAS_CXX_HDR_VARIANT 0
435 #endif
436 #if !defined(IUTEST_HAS_HDR_CXXABI)
438 # define IUTEST_HAS_HDR_CXXABI 0
439 #endif
440 
441 //======================================================================
442 // include
443 #include <iterator>
444 
445 #if IUTEST_HAS_CXX_HDR_ANY
446 # include <any>
447 #endif
448 #if IUTEST_HAS_CXX_HDR_CSTDINT
449 # include <cstdint>
450 #endif
451 #if IUTEST_HAS_CXX_HDR_FILESYSTEM
452 # include <filesystem>
453 #endif
454 #if IUTEST_HAS_CXX_HDR_OPTIONAL
455 # include <optional>
456 #endif
457 #if IUTEST_HAS_CXX_HDR_VARIANT
458 # include <variant>
459 #endif
460 #if IUTEST_HAS_CXX_HDR_CHARCONV
461 # include <charconv>
462 #endif
463 
464 //======================================================================
465 // define
466 #if !defined(IUTEST_HAS_STD_FILESYSTEM)
467 # if defined(ANDROID) || defined(__ANDROID__)
468 # define IUTEST_HAS_STD_FILESYSTEM 0
469 # elif IUTEST_HAS_CXX_HDR_FILESYSTEM && defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703
470 # if !defined(__cpp_lib_experimental_filesystem)
471 # define IUTEST_HAS_STD_FILESYSTEM 1
472 # endif
473 # endif
474 #endif
475 
476 #if !defined(IUTEST_HAS_STD_TO_CHARS)
477 # if defined(__cpp_lib_to_chars) && __cpp_lib_to_chars >= 201611
478 # define IUTEST_HAS_STD_TO_CHARS 1
479 # endif
480 #endif
481 
482 // defaults for feature
483 
485 #if !defined(IUTEST_HAS_STD_BEGIN_END)
486 # define IUTEST_HAS_STD_BEGIN_END 0
487 #endif
488 #if !defined(IUTEST_HAS_STD_DECLVAL)
490 # define IUTEST_HAS_STD_DECLVAL 0
491 #endif
492 #if !defined(IUTEST_HAS_STD_EMPLACE)
494 # define IUTEST_HAS_STD_EMPLACE 0
495 #endif
496 #if !defined(IUTEST_HAS_STD_FILESYSTEM)
498 # define IUTEST_HAS_STD_FILESYSTEM 0
499 #endif
500 #if !defined(IUTEST_HAS_STD_INVOKE)
502 # define IUTEST_HAS_STD_INVOKE 0
503 #endif
504 #if !defined(IUTEST_HAS_STD_QUICK_EXIT)
506 # define IUTEST_HAS_STD_QUICK_EXIT 0
507 #endif
508 #if !defined(IUTEST_HAS_STD_TO_CHARS)
510 # define IUTEST_HAS_STD_TO_CHARS 0
511 #endif
512 
514 #if !defined(IUTEST_USE_EXTERNAL_TR1_TUPLE)
515 # define IUTEST_USE_EXTERNAL_TR1_TUPLE 0
516 #endif
517 #ifndef IUTEST_USE_EXTERNAL_STD_TUPLE
519 # define IUTEST_USE_EXTERNAL_STD_TUPLE 0
520 #endif
521 #if !defined(IUTEST_HAS_STD_TUPLE)
523 # define IUTEST_HAS_STD_TUPLE 0
524 #endif
525 #if !defined(IUTEST_HAS_TR1_TUPLE)
527 # define IUTEST_HAS_TR1_TUPLE 0
528 #endif
529 #if IUTEST_HAS_STD_TUPLE || IUTEST_HAS_TR1_TUPLE || IUTEST_USE_EXTERNAL_TR1_TUPLE || IUTEST_USE_EXTERNAL_STD_TUPLE
531 # if !defined(IUTEST_HAS_TUPLE)
532 # define IUTEST_HAS_TUPLE 1
533 # endif
534 #else
535 # if defined(IUTEST_HAS_TUPLE)
536 # undef IUTEST_HAS_TUPLE
537 # endif
538 # define IUTEST_HAS_TUPLE 0
539 #endif
540 #if !defined(IUTEST_HAS_VARIADIC_TUPLES) && IUTEST_HAS_VARIADIC_TEMPLATES && IUTEST_HAS_TUPLE && IUTEST_HAS_STD_TUPLE
541 # if defined(__clang__)
542 # if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ > 7))
543 # define IUTEST_HAS_VARIADIC_TUPLES 1
544 # endif
545 # else
546 # define IUTEST_HAS_VARIADIC_TUPLES 1
547 # endif
548 #endif
549 #if !defined(IUTEST_HAS_VARIADIC_TUPLES)
550 # define IUTEST_HAS_VARIADIC_TUPLES 0
551 #endif
552 
553 
554 //======================================================================
555 // declare
556 
558 #if !defined(IUTEST_HAS_STD_STR_TO_VALUE)
559 # if IUTEST_HAS_CXX11
560 # if defined(IUTEST_OS_WINDOWS_MINGW)
561 # if defined(__MINGW64__) && (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
562 # define IUTEST_HAS_STD_STR_TO_VALUE 1
563 # endif
564 # else
565 # define IUTEST_HAS_STD_STR_TO_VALUE 1
566 # endif
567 # endif
568 #endif
569 
570 #if !defined(IUTEST_HAS_STD_STR_TO_VALUE)
571 # define IUTEST_HAS_STD_STR_TO_VALUE 0
572 #endif
573 
575 #if !defined(IUTEST_USING_BEGIN_END)
576 # if IUTEST_HAS_STD_BEGIN_END
577 # define IUTEST_USING_BEGIN_END() \
578  using ::std::begin; using ::std::end
579 # else
580 # define IUTEST_USING_BEGIN_END() \
581  using ::iutest::detail::cxx::begin; using ::iutest::detail::cxx::end
582 # endif
583 #endif
584 
585 namespace iutest {
586 namespace detail {
587 namespace cxx
588 {
589 
590 #if IUTEST_HAS_STD_BEGIN_END
591 
592 using ::std::begin;
593 using ::std::end;
594 
595 #else
596 
597 template<typename T> typename T::iterator begin(T& x) { return x.begin(); }
598 template<typename T> typename T::iterator end (T& x) { return x.end(); }
599 
600 template<typename T> typename T::const_iterator begin(const T& x) { return x.begin(); }
601 template<typename T> typename T::const_iterator end (const T& x) { return x.end(); }
602 
603 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
604 template<typename T, size_t SIZE> T* begin(T (&x)[SIZE]) { return &x[0]; }
605 template<typename T, size_t SIZE> T* end (T (&x)[SIZE]) { return begin(x) + SIZE; }
606 
607 template<typename T, size_t SIZE> const T* begin(const T (&x)[SIZE]) { return &x[0]; }
608 template<typename T, size_t SIZE> const T* end (const T (&x)[SIZE]) { return begin(x) + SIZE; }
609 #endif
610 
611 #endif
612 
613 } // end of namespace cxx
614 } // end of namespace detail
615 } // end of namespace iutest
616 
617 #if IUTEST_HAS_TUPLE
618 #if !IUTEST_USE_EXTERNAL_STD_TUPLE && !IUTEST_USE_EXTERNAL_TR1_TUPLE
619 # if IUTEST_HAS_STD_TUPLE
620 # include <tuple>
621 # elif IUTEST_HAS_TR1_TUPLE
622 # if (defined(__GNUC__) && (__GNUC__ >= 4))
623 # include <tr1/tuple>
624 # else
625 # include <tuple>
626 # endif
627 # endif
628 #endif
629 
630 namespace iutest {
631 namespace tuples
632 {
633 
634 #if IUTEST_HAS_STD_TUPLE
635 namespace alias = ::std;
636 #elif IUTEST_HAS_TR1_TUPLE
637 namespace alias = ::std::tr1;
638 #endif
639 
640 using alias::tuple;
641 using alias::tuple_element;
642 using alias::make_tuple;
643 using alias::get;
644 
645 template<typename T>struct tuple_size : public alias::tuple_size<T> {};
646 template<typename T>struct tuple_size<const T> : public alias::tuple_size<T> {};
647 template<typename T>struct tuple_size<volatile T> : public alias::tuple_size<T>{};
648 template<typename T>struct tuple_size<const volatile T> : public alias::tuple_size<T>{};
649 
650 namespace detail
651 {
652 
653 template<typename T, typename F, int Begin>
654 struct tuple_foreach_impl
655 {
656  template<int N, int I>
657  struct impl
658  {
659  static void do_something(T& t, F fn)
660  {
661  fn(I, get<I>(t));
662  impl<N, I + 1>::do_something(t, fn);
663  }
664  };
665  template<int N>
666  struct impl<N, N>
667  {
668  static void do_something(T&, F) {}
669  };
670 
671  static void do_something(T& t, F fn)
672  {
673  impl<tuple_size<T>::value, Begin>::do_something(t, fn);
674  }
675 };
676 
677 template<typename T, typename U>
678 struct tuple_cast_copy_impl
679 {
680  template<int N, int I>
681  struct impl
682  {
683  static void copy(T& dst, const U& src)
684  {
685  get<I>(dst) = static_cast<typename tuple_element<I, T>::type>(get<I>(src));
686  impl<N, I + 1>::copy(dst, src);
687  }
688  };
689  template<int N>
690  struct impl<N, N>
691  {
692  static void copy(T&, const U&) {}
693  };
694 
695  static void copy(T& dst, const U& src)
696  {
697  impl<tuple_size<T>::value, 0>::copy(dst, src);
698  }
699 };
700 
701 } // end of namespace detail
702 
703 template<int I, typename tuple_t, typename F>
704 void tuple_foreach(tuple_t& t, F& fn)
705 {
706  detail::tuple_foreach_impl<tuple_t, F&, I>::do_something(t, fn);
707 }
708 template<typename tuple_t, typename F>
709 void tuple_foreach(tuple_t& t, F& fn)
710 {
711  tuple_foreach<0>(t, fn);
712 }
713 template<int I, typename tuple_t, typename F>
714 void tuple_foreach(tuple_t& t, const F& fn)
715 {
716  detail::tuple_foreach_impl<tuple_t, const F&, I>::do_something(t, fn);
717 }
718 template<typename tuple_t, typename F>
719 void tuple_foreach(tuple_t& t, const F& fn)
720 {
721  tuple_foreach<0>(t, fn);
722 }
723 template<typename T, typename U>
724 void tuple_cast_copy(T& dst, const U& src)
725 {
726  detail::tuple_cast_copy_impl<T, U>::copy(dst, src);
727 }
728 
729 } // end of namespace tuples
730 
731 using tuples::tuple;
732 using tuples::tuple_size;
733 using tuples::tuple_element;
734 using tuples::tuple_foreach;
735 using tuples::make_tuple;
736 using tuples::get;
737 
738 } // end of namespace iutest
739 
740 #endif
741 
743 #if !defined(IUTEST_HAS_HDR_SYSTIME)
744 # if defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_MINGW) && !defined(IUTEST_OS_WINDOWS_WINE)
745 # define IUTEST_HAS_HDR_SYSTIME 0
746 # endif
747 #endif
748 
749 #if !defined(IUTEST_HAS_HDR_SYSTIME)
750 # define IUTEST_HAS_HDR_SYSTIME 1
751 #endif
752 
753 // socklen_t
754 #if defined(IUTEST_OS_WINDOWS_WINE)
755 # define __socklen_t_defined
756 #endif
757 
759 #if !defined(IUTEST_HAS_STRINGSTREAM)
760 # if !defined(_STLP_NO_IOSTREAMS)
761 # define IUTEST_HAS_STRINGSTREAM 1
762 # endif
763 #endif
764 
765 #if !defined(IUTEST_HAS_STRINGSTREAM)
766 # define IUTEST_HAS_STRINGSTREAM 0
767 #endif
768 
769 
775 #if !defined(IUTEST_HAS_STRSTREAM)
776 # define IUTEST_HAS_STRSTREAM 0
777 #endif
778 
780 #if !defined(IUTEST_HAS_IOMANIP)
781 # if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM
782 # define IUTEST_HAS_IOMANIP 1
783 # endif
784 #endif
785 
786 #if !defined(IUTEST_HAS_IOMANIP)
787 # define IUTEST_HAS_IOMANIP 0
788 #endif
789 
790 
792 #if !defined(IUTEST_HAS_INVALID_PARAMETER_HANDLER)
793 # if IUTEST_HAS_EXCEPTIONS && (defined(_MSC_VER) && (_MSC_VER >= 1400)) && !defined(IUTEST_OS_WINDOWS_MOBILE)
794 # define IUTEST_HAS_INVALID_PARAMETER_HANDLER 1
795 # endif
796 #endif
797 
798 #if !defined(IUTEST_HAS_INVALID_PARAMETER_HANDLER)
799 # define IUTEST_HAS_INVALID_PARAMETER_HANDLER 0
800 #endif
801 
803 #if !defined(IUPRzu)
804 # if defined(_MSC_VER) && (_MSC_VER < 1900)
805 # define IUPRzu "Iu"
806 # elif defined(IUTEST_OS_WINDOWS_MINGW)
807 # if !defined(__STRICT_ANSI__)
808 # if defined(__MINGW64__)
809 # define IUPRzu PRIu64
810 # elif defined(__MINGW32__)
811 # define IUPRzu PRIu32
812 # endif
813 # endif
814 # endif
815 #endif
816 
817 #if !defined(IUPRzu)
818 # define IUPRzu "zu"
819 #endif
820 
821 #if !defined(iu_va_copy)
822 # if defined(va_copy)
823 # define iu_va_copy va_copy
824 # elif defined(__GNUC__) || defined(__clang__)
825 # define iu_va_copy(dest, src) __builtin_va_copy(dest, src)
826 # else
827 # define iu_va_copy(dest, src) (dest = src)
828 # endif
829 #endif
830 
831 namespace iutest {
832 namespace detail
833 {
834 
835 //======================================================================
836 // struct
840 template<int SIZE>
841 struct type_least_t {};
842 
844 template<>
845 struct type_least_t<1>
846 {
847 #if defined(INT_LEAST8_MIN)
848  typedef int_least8_t Int;
849  typedef uint_least8_t UInt;
850 #else
851  typedef char Int;
852  typedef unsigned char UInt;
853 #endif
854 };
855 
857 template<>
858 struct type_least_t<2>
859 {
860 #if defined(INT_LEAST16_MIN)
861  typedef int_least16_t Int;
862  typedef uint_least16_t UInt;
863 #else
864  typedef short Int;
865  typedef unsigned short UInt;
866 #endif
867 };
868 
870 template<>
871 struct type_least_t<4>
872 {
873 #if defined(INT_LEAST32_MIN)
874  typedef int_least32_t Int;
875  typedef uint_least32_t UInt;
876 #else
877  typedef int Int;
878  typedef unsigned int UInt;
879 #endif
880 };
881 
883 template<>
884 struct type_least_t<8>
885 {
886 #if defined(INT_LEAST64_MIN)
887  typedef int_least64_t Int;
888  typedef uint_least64_t UInt;
889 #else
890 #if defined(_MSC_VER)
891  typedef __int64 Int;
892  typedef unsigned __int64 UInt;
893 #else
894  typedef long long Int;
895  typedef unsigned long long UInt;
896 #endif
897 #endif
898 };
899 
903 template<size_t SIZE>
904 struct type_fit_t {};
905 
907 template<>
908 struct type_fit_t<1>
909 {
910 #if defined(INT8_MIN)
911  typedef int8_t Int;
912  typedef uint8_t UInt;
913 #else
914  typedef char Int;
915  typedef unsigned char UInt;
916 #endif
917 };
918 
920 template<>
921 struct type_fit_t<2>
922 {
923 #if defined(INT16_MIN)
924  typedef int16_t Int;
925  typedef uint16_t UInt;
926 #else
927  typedef short Int;
928  typedef unsigned short UInt;
929 #endif
930 };
931 
933 template<>
934 struct type_fit_t<4>
935 {
936 #if defined(INT32_MIN)
937  typedef int32_t Int;
938  typedef uint32_t UInt;
939 #else
940 #if !defined(IUTEST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
941 private:
942  template<typename T, typename F, bool b>
943  struct impl { typedef T type; };
944  template<typename T, typename F>
945  struct impl<T, F, false> { typedef F type; };
946 
947 public:
948  typedef impl<long, int
949  , sizeof(int) != 4 && sizeof(long) == 4>::type Int;
950  typedef impl<unsigned long, unsigned int
951  , sizeof(int) != 4 && sizeof(long) == 4>::type UInt;
952 #else
953  typedef int Int;
954  typedef unsigned int UInt;
955 #endif
956 #endif
957 };
958 
960 template<>
961 struct type_fit_t<8>
962 {
963 #if defined(INT64_MIN)
964  typedef int64_t Int;
965  typedef uint64_t UInt;
966 #else
967 #if defined(_MSC_VER)
968  typedef __int64 Int;
969  typedef unsigned __int64 UInt;
970 #else
971  typedef long long Int;
972  typedef unsigned long long UInt;
973 #endif
974 #endif
975 };
976 
978 template<>
979 struct type_fit_t<16>
980 {
981 #if IUTEST_HAS_INT128
982 #if defined(_MSC_VER)
983  typedef __int128 Int;
984  typedef unsigned __int128 UInt;
985 #else
986  typedef __int128_t Int;
987  typedef __uint128_t UInt;
988 #endif
989 #endif
990 };
991 
992 //======================================================================
993 // function
998 inline int iu_mbtowc(wchar_t* dst, const char* src, size_t size)
999 {
1000 #if defined(IUTEST_OS_LINUX_ANDROID) || defined(IUTEST_OS_WINDOWS_MOBILE)
1001  // unimplimented
1002  IUTEST_UNUSED_VAR(dst);
1003  IUTEST_UNUSED_VAR(src);
1004  IUTEST_UNUSED_VAR(size);
1005  return 0;
1006 #else
1007  return mbtowc(dst, src, size);
1008 #endif
1009 }
1010 
1011 } // end of namespace detail
1012 } // end of namespace iutest
1013 
1014 #endif // INCG_IRIS_IUTEST_STDLIB_HPP_54D4BEEE_7B6B_4AF4_B1F6_138560480D55_
iutest_config.hpp
iris unit test config
iutest
iutest root namespace
Definition: iutest_charcode.hpp:31