YSTest: ydef.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

ydef.h
浏览该文件的文档.
1 /*
2 © 2009-2020 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
36 #ifndef YB_INC_ydef_h_
37 #define YB_INC_ydef_h_ 1
38
44
82 #if defined(__GNUC__)
83 # undef YB_IMPL_GNUC
84 # define YB_IMPL_GNUC \
85 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
86 #endif
87 // XXX: Some implementations may not properly support the macros. See
88 // https://docs.microsoft.com/cpp/build/reference/zc-cplusplus and
89 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773 for instance.
90 #ifdef __cplusplus
91 # if defined(_MSC_VER) && !defined(__clang__)
92 # undef YB_IMPL_MSCPP
93 # define YB_IMPL_MSCPP _MSC_VER
94 # elif defined(__clang__)
95 # undef YB_IMPL_CLANGPP
96 # if defined(__apple_build_version__)
97 # define YB_IMPL_CLANGPP (40300 + __clang_patchlevel__)
98 # else
99 # define YB_IMPL_CLANGPP \
100 (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
101 # endif
102 # elif defined(__GNUG__)
103 # undef YB_IMPL_GNUCPP
104 # define YB_IMPL_GNUCPP \
105 (__GNUG__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
106 # else
107 // TODO: Deferred. Complete version checking for compiler and library
108 // implementations, e.g. EDG frontends.
109 //#ifdef __GNUC__
110 //# include <tr1/type_traits>
111 # error "This language implementation is not supported."
112 # endif
113 #else
114 # error "This header is only for C++."
115 #endif
116
117 #if YB_IMPL_MSCPP >= 1400
118 # ifndef _CRT_SECURE_NO_WARNINGS
120 # define _CRT_SECURE_NO_WARNINGS
121 # endif
122 # ifndef _SCL_SECURE_NO_WARNINGS
124 # define _SCL_SECURE_NO_WARNINGS
125 # endif
126 #endif
127
128
138 #ifndef __has_attribute
139 # define __has_attribute(...) 0
140 #endif
141
147 #ifndef __has_builtin
148 # define __has_builtin(...) 0
149 #endif
150
155 #ifndef __has_cpp_attribute
156 # define __has_cpp_attribute(...) 0
157 #endif
158
160
161 #ifndef __has_extension
162 # define __has_extension(...) 0
163 #endif
164
165 #ifndef __has_feature
166 # define __has_feature(...) 0
167 #endif
168
169
174 #ifndef __has_include
175 # define __has_include(...) 0
176 #endif
177
178
180
181
186
188 #ifndef __cpp_constexpr
189 # if __has_feature(cxx_relaxed_constexpr) || __cplusplus >= 201304L
190 # define __cpp_constexpr 201304L
191 # elif __has_feature(cxx_constexpr) || __cplusplus >= 200704L \
192 || YB_IMPL_GNUCPP >= 40600 || YB_IMPL_MSCPP >= 1900
193 # define __cpp_constexpr 200704L
194 # endif
195 #endif
196
197
205 #ifndef __cpp_inheriting_constructors
206 # if (YB_IMPL_MSCPP >= 1914 && _MSVC_LANG >= 201511) || __cplusplus >= 201511L
207 # define __cpp_inheriting_constructors 201511L
208 # elif __has_feature(cxx_inheriting_constructors) || YB_IMPL_MSCPP > 1900 \
209 || __cplusplus >= 200802L
210 # define __cpp_inheriting_constructors 200802L
211 # endif
212 #endif
213
214
220 // NOTE: Microsoft VC++ compiler has support the feature since version 15.5.
221 // However, the %__cplusplus can only work after 15.7 Preview 3 with
222 // additional option It can be more precise when %_MSC_FULL_VER is
223 // incorperated, but there is lack of documentation so additional test work is
224 // needed to make the improvement.
225 #ifndef __cpp_inline_variables
226 # if __has_feature(cxx_inline_variables) \
227 || __has_extension(cxx_inline_variables) || YB_IMPL_MSCPP > 1912 \
228 || __cplusplus >= 201606L
229 # define __cpp_inline_variables 201606L
230 # endif
231 #endif
232
233
239 // NOTE: Ditto about Microsoft VC++ support as %__cpp_inline_variables.
240 #ifndef __cpp_noexcept_function_type
241 # if __has_feature(cxx_noexcept_function_type) \
242 || __has_extension(cxx_noexcept_function_type) || YB_IMPL_MSCPP > 1912 \
243 || __cplusplus >= 201510L
244 # define __cpp_noexcept_function_type 201510L
245 # endif
246 #endif
247
248
249
250 #include <cstddef> // for __cpp_lib_byte, std::byte, std::nullptr_t,
251 // std::size_t, std::ptrdiff_t, offsetof;
252 #include <cstdlib> // for std::abort;
253 #include <climits> // for CHAR_BIT;
254 #include <cstdint> // for std::uint8_t;
255 #include <cassert> // for assert;
256 #include <cwchar> // for std::wint_t;
257 #include <utility> // for std::forward;
258 #include <type_traits> // for std::is_class, std::is_standard_layout;
259
272 #ifndef __cpp_lib_byte
273 # if ((YB_IMPL_MSCPP >= 1911 && _MSVC_LANG >= 201603) \
274 || YB_IMPL_GCC >= 70100 || __cplusplus >= 201603L) \
275 && !(YB_IMPL_MSCPP >= 1911 && _MSVC_LANG >= 201603 && _HAS_STD_BYTE != 0)
276 # define __cpp_lib_byte 201603L
277 # endif
278 #endif
279
280
286 #ifndef __cpp_lib_bool_constant
287 # if YB_IMPL_MSCPP >= 1900 || __cplusplus >= 201505L
288 # define __cpp_lib_bool_constant 201505L
289 # endif
290 #endif
291
293 #ifndef __cpp_lib_is_invocable
294 # if (YB_IMPL_MSCPP >= 1911 && _MSVC_LANG >= 201703) || __cplusplus >= 201703L
295 # define __cpp_lib_is_invocable 201703L
296 # endif
297 #endif
298 #ifndef __cpp_lib_is_null_pointer
299 # if YB_IMPL_MSCPP >= 1900 || __cplusplus >= 201309L
300 # define __cpp_lib_is_null_pointer 201309L
301 # endif
302 #endif
303
305 #ifndef __cpp_lib_is_swappable
306 # if YB_IMPL_MSCPP > 1900 || __cplusplus >= 201603L
307 # define __cpp_lib_is_swappable 201603L
308 # endif
309 #endif
310
311 #ifndef __cpp_lib_transformation_trait_aliases
312 # if YB_IMPL_MSCPP >= 1800 || __cplusplus >= 201304L
313 # define __cpp_lib_transformation_trait_aliases 201304L
314 # endif
315 #endif
316
317 #ifndef __cpp_lib_void_t
318 # if YB_IMPL_MSCPP >= 1900 || __cplusplus >= 201411L
319 # define __cpp_lib_void_t 201411L
320 # endif
321 #endif
322
323
329
331 #ifndef __cpp_lib_as_const
332 # if YB_IMPL_MSCPP >= 1911 || __cplusplus >= 201510L
333 # define __cpp_lib_as_const 201510L
334 # endif
335 #endif
336
337 #ifndef __cpp_lib_exchange_function
338 # if YB_IMPL_MSCPP >= 1900 || __cplusplus >= 201304L
339 # define __cpp_lib_exchange_function 201304L
340 # endif
341 #endif
342 #ifndef __cpp_lib_integer_sequence
343 # if YB_IMPL_MSCPP >= 1900 || __cplusplus >= 201304L
344 # define __cpp_lib_integer_sequence 201304L
345 # endif
346 #endif
347
348
349
350
361 #define YPP_Args(...) __VA_ARGS__
362
364 #define YPP_Empty
365
370 #define YPP_Comma ,
371
376 #define YPP_Concat(_x, _y) _x ## _y
377
387 #define YPP_Join(_x, _y) YPP_Concat(_x, _y)
388
393 #define YPP_Stringify(_x) #_x
394
399 #define YPP_Stringize(_x) YPP_Stringify(_x)
400
401
402
413 #define yimpl(...) __VA_ARGS__
414
415
417
418
430 #if YB_IMPL_CLANGPP
431 # define YB_Diag_Push _Pragma("clang diagnostic push")
432 # define YB_Diag_Pop _Pragma("clang diagnostic pop")
433 # define YB_Diag_Ignore(_opt) _Pragma( \
434 YPP_Stringize(clang diagnostic ignored YPP_Stringize(YPP_Concat(-W, _opt))))
435 #elif YB_IMPL_GNUCPP >= 40600
436 # define YB_Diag_Push _Pragma("GCC diagnostic push")
437 # define YB_Diag_Pop _Pragma("GCC diagnostic pop")
438 # define YB_Diag_Ignore(_opt) _Pragma( \
439 YPP_Stringize(GCC diagnostic ignored YPP_Stringize(YPP_Concat(-W, _opt))))
440 #else
441 # define YB_Diag_Push
442 # define YB_Diag_Pop
443 # define YB_Diag_Ignore
444 #endif
445
446
447
476 #undef YB_HAS_ALIGNAS
477 #define YB_HAS_ALIGNAS (__has_feature(cxx_alignas) \
478 || __has_extension(cxx_alignas) || __cplusplus >= 201103L \
479 || YB_IMPL_GNUCPP >= 40800 || YB_IMPL_MSCPP >= 1800)
480
487 #undef YB_HAS_ALIGNOF
488 #define YB_HAS_ALIGNOF (__has_feature(cxx_alignof) \
489 || __has_extension(cxx_alignof) || __cplusplus >= 201103L \
490 || YB_IMPL_GNUCPP >= 40500 || YB_IMPL_MSCPP >= 1800)
491
497 #undef YB_HAS_BUILTIN_NULLPTR
498 #define YB_HAS_BUILTIN_NULLPTR \
499 (__has_feature(cxx_nullptr) || __has_extension(cxx_nullptr) \
500 || __cplusplus >= 201103L || YB_IMPL_GNUCPP >= 40600 || \
501 YB_IMPL_MSCPP >= 1600)
502
508 #undef YB_HAS_NOEXCEPT
509 #define YB_HAS_NOEXCEPT \
510 (__has_feature(cxx_noexcept) || __has_extension(cxx_noexcept) || \
511 __cplusplus >= 201103L || YB_IMPL_GNUCPP >= 40600 \
512 || YB_IMPL_MSCPP >= 1900)
513
521 #undef YB_HAS_THREAD_LOCAL
522 // XXX: The macro %_GLIBCXX_HAVE_TLS is independ on the mode used. For all
523 // versions of G++ having unreliable %__cplusplus, 'thread_local' is assumed
524 // not supported.
525 #define YB_HAS_THREAD_LOCAL \
526 (__has_feature(cxx_thread_local) || (__cplusplus >= 201103L \
527 && (!YB_IMPL_GNUCPP || _GLIBCXX_HAVE_TLS)) || YB_IMPL_MSCPP >= 1900)
528
529
530
537 #if __has_builtin(__builtin_trap) || YB_IMPL_GNUCPP >= 40203
538 # define YB_ABORT __builtin_trap()
539 #else
540 # define YB_ABORT std::abort()
541 #endif
542
543
564 #if YB_IMPL_GNUC >= 20500
565 # define YB_ATTR(...) __attribute__((__VA_ARGS__))
566 #else
567 # define YB_ATTR(...)
568 #endif
569
580 #if !(YB_IMPL_GNUCPP && YB_IMPL_GNUCPP >= 90000)
581 # define YB_ATTR_LAMBDA(...) YB_ATTR(__VA_ARGS__)
582 #else
583 # define YB_ATTR_LAMBDA(...)
584 #endif
585
618 #if !(YB_IMPL_GNUCPP && YB_IMPL_GNUCPP < 90100) && !YB_IMPL_CLANGPP
619 # define YB_ATTR_LAMBDA_QUAL(_q, ...) _q __VA_ARGS__
620 #else
621 # define YB_ATTR_LAMBDA_QUAL(_q, ...) __VA_ARGS__ _q
622 #endif
623
624
632 #if __cpp_attributes >= 200809L || __has_feature(cxx_attributes)
633 # define YB_ATTR_STD(...) [[__VA_ARGS__]]
634 #else
635 # define YB_ATTR_STD(...)
636 #endif
637
644 #if __has_cpp_attribute(fallthrough) \
645 && (!YB_IMPL_CLANGPP || __cplusplus >= 201703L)
646 // XXX: This is ruled out for [-Wc++17-extensions] in Clang++.
647 # define YB_ATTR_fallthrough YB_ATTR_STD(fallthrough)
648 #elif __has_cpp_attribute(clang::fallthrough)
649 # define YB_ATTR_fallthrough YB_ATTR_STD(clang::fallthrough)
650 #elif __has_cpp_attribute(gnu::fallthrough)
651 # define YB_ATTR_fallthrough YB_ATTR_STD(gnu::fallthrough)
652 #elif __has_attribute(__fallthrough__)
653 # define YB_ATTR_fallthrough YB_ATTR(__fallthrough__)
654 #else
655 # define YB_ATTR_fallthrough
656 #endif
657
665 #if YB_IMPL_GNUCPP >= 40400
666 # define YB_ATTR_gnu_printf(...) \
667 YB_ATTR(__format__(__gnu_printf__, __VA_ARGS__))
668 #elif __has_cpp_attribute(format) || YB_IMPL_GNUCPP >= 20604
669 # define YB_ATTR_gnu_printf(...) YB_ATTR(__format__(__printf__, __VA_ARGS__))
670 #else
671 # define YB_ATTR_gnu_printf(...)
672 #endif
673
682 #if __has_cpp_attribute(maybe_unused)
683 # define YB_ATTR_maybe_unused YB_ATTR_STD(maybe_unused)
684 #elif __has_cpp_attribute(gnu::unused)
685 # define YB_ATTR_maybe_unused YB_ATTR_STD(gnu::unused)
686 #elif __has_attribute(__unused__)
687 # define YB_ATTR_maybe_unused YB_ATTR(__unused__)
688 #else
689 # define YB_ATTR_maybe_unused
690 #endif
691
701 #if __has_cpp_attribute(nodiscard) \
702 && (!YB_IMPL_CLANGPP || __cplusplus >= 201703L)
703 // XXX: This is ruled out for [-Wc++17-extensions] in Clang++.
704 # define YB_ATTR_nodiscard YB_ATTR_STD(nodiscard)
705 #elif __has_cpp_attribute(clang::warn_unused_result)
706 # define YB_ATTR_nodiscard YB_ATTR_STD(clang::warn_unused_result)
707 #elif __has_cpp_attribute(gnu::warn_unused_result)
708 # define YB_ATTR_nodiscard YB_ATTR_STD(gnu::warn_unused_result)
709 #elif __has_attribute(__warn_unused_result__)
710 # define YB_ATTR_nodiscard YB_ATTR(__warn_unused_result__)
711 #elif YB_IMPL_MSCPP >= 1700
712 // XXX: Assume SAL is available.
713 # define YB_ATTR_nodiscard _Check_return_
714 #else
715 # define YB_ATTR_nodiscard
716 #endif
717
740 #if __has_cpp_attribute(novtable)
741 # define YB_ATTR_novtable YB_ATTR(novtable)
742 #elif YB_IMPL_MSCPP >= 1100 || (YB_IMPL_CLANGPP >= 30700 && YB_IMPL_MSCPP)
743 # define YB_ATTR_novtable __declspec(novtable)
744 #else
745 # define YB_ATTR_novtable
746 #endif
747
757 #if __has_attribute(__returns_nonnull__) || YB_IMPL_GNUCPP >= 40900 \
758 || YB_IMPL_CLANGPP >= 30500
759 # define YB_ATTR_returns_nonnull YB_ATTR(__returns_nonnull__)
760 #else
761 # define YB_ATTR_returns_nonnull
762 #endif
763
778 #if YB_IMPL_MSCPP >= 1900 && !defined(__EDG__) && !defined _CORECRT_BUILD
779 # define YB_ALLOCATOR __declspec(allocator) __declspec(restrict)
780 #elif YB_IMPL_MSCPP >= 1400
781 # define YB_ALLOCATOR YB_ATTR_nodiscard __declspec(restrict)
782 #elif __has_attribute(__malloc__) || YB_IMPL_GNUCPP >= 20296
783 # define YB_ALLOCATOR YB_ATTR_nodiscard YB_ATTR(__malloc__)
784 #else
785 # define YB_ALLOCATOR YB_ATTR_nodiscard
786 #endif
787
800 #if YB_IMPL_MSCPP >= 1200
801 # define YB_ASSUME(_expr) __assume(_expr)
802 #elif YB_IMPL_CLANGPP >= 30501
803 // NOTE: The warning [-Wassume ]is largely useless with misleading diagnostics.
804 # define YB_ASSUME(_expr) \
805 YB_Diag_Push YB_Diag_Ignore(assume) __builtin_assume(_expr) YB_Diag_Pop
806 #elif __has_builtin(__builtin_assume)
807 # define YB_ASSUME(_expr) __builtin_assume(_expr)
808 #elif __has_builtin(__builtin_unreachable) || YB_IMPL_GNUCPP >= 40500
809 # define YB_ASSUME(_expr) ((_expr) ? void() : __builtin_unreachable())
810 #else
811 # define YB_ASSUME(_expr) ((_expr) ? void() : YB_ABORT)
812 #endif
813
821 #if __has_builtin(__builtin_expect) || YB_IMPL_GNUCPP >= 29600
822 # define YB_EXPECT(_expr, _constant) (__builtin_expect(_expr, _constant))
823 # define YB_LIKELY(_expr) (__builtin_expect(bool(_expr), 1))
824 # define YB_UNLIKELY(_expr) (__builtin_expect(bool(_expr), 0))
825 #else
826 # define YB_EXPECT(_expr, _constant) (_expr)
827 # define YB_LIKELY(_expr) (_expr)
828 # define YB_UNLIKELY(_expr) (_expr)
829 #endif
830
839 #if (__has_attribute(__flatten__) || (YB_IMPL_GNUCPP >= 40102 \
840 && YB_IMPL_GNUCPP != 40600) || YB_IMPL_CLANGPP >= 30402)
841 # define YB_FLATTEN YB_ATTR(__flatten__)
842 #else
843 # define YB_FLATTEN
844 #endif
845
853 #if __has_attribute(__nonnull__) || YB_IMPL_GNUCPP >= 30300
854 # define YB_NONNULL(...) YB_ATTR(__nonnull__(__VA_ARGS__))
855 #else
856 # define YB_NONNULL(...)
857 #endif
858
869 #if __has_cpp_attribute(noreturn) >= 200809 || YB_IMPL_MSCPP >= 1900 \
870 || YB_IMPL_GNUCPP >= 40800 || __cplusplus >= 201103L
871 # define YB_NORETURN [[noreturn]]
872 #elif __has_attribute(__noreturn__) || YB_IMPL_GNUCPP >= 20296
873 # define YB_NORETURN YB_ATTR(__noreturn__)
874 #elif YB_IMPL_MSCPP >= 1200
875 # define YB_NORETURN __declspec(noreturn)
876 #else
877 # define YB_NORETURN
878 #endif
879
880 #if YB_IMPL_MSCPP >= 1200
881 # pragma warning(disable: 4646)
883 #endif
884
912 // XXX: The conditions latter implies '_LIBUNWIND_ARM_EHABI' in libunwind and
913 // '_LIBCXXABI_ARM_EHABI' in libc++.
914 #if (__has_attribute(__pure__) || YB_IMPL_GNUCPP >= 20296) \
915 && !(YB_IMPL_CLANGPP && defined(__arm__) \
916 && !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__ARM_DWARF_EH__))
917 # define YB_PURE YB_ATTR(__pure__)
918 #else
919 # define YB_PURE
920 #endif
921
938 #if __has_attribute(__const__) || YB_IMPL_GNUCPP >= 20500
939 # define YB_STATELESS YB_ATTR(__const__)
940 #else
941 # define YB_STATELESS
942 #endif
943
944
945
946
968 #if defined(YB_DLL) && defined(YB_BUILD_DLL)
969 # error "DLL could not be built and used at the same time."
970 #endif
971
972 #if YB_IMPL_MSCPP \
973 || (YB_IMPL_GNUC && (defined(__MINGW32__) || defined(__CYGWIN__)))
974 # ifdef YB_DLL
975 # define YB_API __declspec(dllimport)
976 # elif defined(YB_BUILD_DLL)
977 # define YB_API __declspec(dllexport)
978 # else
979 # define YB_API
980 # endif
981 #elif defined(YB_BUILD_DLL) && (__has_attribute(__visibility__) \
982 || YB_IMPL_GNUCPP >= 40000 || YB_IMPL_CLANGPP)
983 # define YB_API YB_ATTR(__visibility__("default"))
984 #else
985 # define YB_API
986 #endif
987
988
994 #if false && !defined(NDEBUG)
995 # define YB_Use_DynamicExceptionSpecification 1
996 #endif
997
1013 #ifndef NDEBUG
1014 # ifndef YB_Use_YAssert
1015 # define YB_Use_YAssert 1
1016 # endif
1017 #elif !defined(YB_Use_StrictNoThrow)
1018 # define YB_Use_StrictNoThrow 1
1019 #endif
1020 #define YB_Use_YTrace 1
1021
1022
1023
1036 #if YB_HAS_ALIGNAS
1037 # define yalignas alignas
1038 # define yalignas_type alignas
1039 #else
1040 # define yalignas(_expr) YB_ATTR(__aligned__(_expr))
1041 # define yalignas_type(_type) YB_ATTR(__aligned__(__alignof(_type)))
1042 #endif
1043
1050 #if YB_HAS_ALIGNOF
1051 # define yalignof alignof
1052 #else
1053 # define yalignof(_type) std::alignment_of<_type>::value
1054 #endif
1055
1068 #if __cpp_constexpr >= 200704L
1069 # define yconstexpr constexpr
1070 # define yconstfn constexpr
1071 #else
1072 # define yconstexpr
1073 # define yconstfn inline
1074 #endif
1075
1082 #if __cpp_inline_variables >= 201606L
1083 # define yconstexpr_inline inline yconstexpr
1084 #else
1085 # define yconstexpr_inline yconstexpr
1086 #endif
1087
1094 #if __cpp_constexpr >= 201304L
1095 # define yconstfn_relaxed constexpr
1096 #else
1097 # define yconstfn_relaxed inline
1098 #endif
1099
1106 #if YB_IMPL_MSCPP || __INTEL_COMPILER >= 600 || __IBMCPP__ >= 500
1107 # define yfname __FUNCTION__
1108 #elif __BORLANDC__ >= 0x550
1109 # define yfname __FUNC__
1110 #elif __cplusplus >= 201103 || __STDC_VERSION__ >= 199901
1111 # define yfname __func__
1112 #else
1113 # define yfname "<unknown-fn>"
1114 #endif
1115
1122 #if YB_IMPL_GNUCPP || YB_IMPL_CLANGPP
1123 # define yfsig __PRETTY_FUNCTION__
1124 #elif defined(__FUNCSIG__)
1125 # define yfsig __FUNCSIG__
1126 #elif __INTEL_COMPILER >= 600 || __IBMCPP__ >= 500
1127 # define yfsig __FUNCTION__
1128 #elif __BORLANDC__ >= 0x550
1129 # define yfsig __FUNC__
1130 #elif __cplusplus >= 201103 || __STDC_VERSION__ >= 199901
1131 # define yfsig __func__
1132 #else
1133 # define yfsig "<unknown-fsig>"
1134 #endif
1135
1146 #if YB_HAS_NOEXCEPT
1147 # define ynoexcept noexcept
1148 # define ynoexcept_assert(_msg, ...) \
1149 static_assert(noexcept(__VA_ARGS__), _msg)
1150 #else
1151 # define ynoexcept(...)
1152 # define ynoexcept_assert(_msg, ...)
1153 #endif
1154
1165 #if __cpp_noexcept_function_type >= 201510L
1166 # if !YB_HAS_NOEXCEPT
1167 # error "Invalid language implementation found."
1168 # endif
1169 # define ynoexcept_param(_n) , bool _n
1170 # define ynoexcept_qual(...) noexcept(__VA_ARGS__)
1171 #else
1172 # define ynoexcept_param(_n)
1173 # define ynoexcept_qual(...)
1174 #endif
1175
1181 #define ynoexcept_spec(...) ynoexcept(noexcept(__VA_ARGS__))
1182
1194 #if YB_HAS_NOEXCEPT
1195 # define ynothrow ynoexcept
1196 #elif YB_IMPL_GNUCPP >= 30300
1197 # define ynothrow __attribute__((nothrow))
1198 #else
1199 # define ynothrow ythrow()
1200 #endif
1201
1216 #if YB_Use_StrictNoThrow
1217 # define ynothrowv ynothrow
1218 #else
1219 # define ynothrowv
1220 #endif
1221
1229 // XXX: %_MT is specific to Win32 and it is not considered a prerequisition of
1230 // TLS now.
1231 #if YB_HAS_THREAD_LOCAL
1232 # define ythread thread_local
1233 // TODO: Versions?
1234 #elif defined(_WIN32) && (YB_IMPL_MSCPP || defined(__ICL) || defined(__DMC__) \
1235 || defined(__BORLANDC__))
1236 # define ythread __declspec(thread)
1237 // Old versions of Mac OS do not support '__thread'. Other platforms compatible
1238 // to GNU C should support it.
1239 #elif (defined(__APPLE__) && YB_IMPL_CLANGPP && defined(MAC_OS_X_VERSION_10_7) \
1240 && (defined(__x86_64__) || defined(__i386__))) || YB_IMPL_GUNC
1241 # define ythread __thread
1242 #else
1243 # define ythread
1244 #endif
1245
1253 #if YB_Use_DynamicExceptionSpecification
1254 # define ythrow throw
1255 #else
1256 # define ythrow(...)
1257 #endif
1258
1259
1260
1261 namespace ystdex
1262 {
1263
1280 #if __cpp_lib_byte >= 201603L
1281 using std::byte;
1282 #else
1283 using byte = unsigned char;
1284 #endif
1285
1286 #if CHAR_BIT == 8
1287
1292 using octet = std::uint8_t;
1293 # else
1294 using octet = void;
1295 #endif
1296
1297 using std::ptrdiff_t;
1298 using std::size_t;
1299 using std::wint_t;
1300
1301 #if YB_IMPL_MSCPP && defined(__cplusplus_cli)
1302 using nullptr_t = decltype(__nullptr);
1304 #elif YB_HAS_BUILTIN_NULLPTR
1305 using std::nullptr_t;
1307 #else
1308
1320 yconstexpr const class nullptr_t
1321 {
1322 public:
1324 void
1325 operator&() const = delete;
1326
1328
1329
1331 template<typename _type>
1332 YB_ATTR_nodiscard YB_STATELESS friend yconstfn bool
1333 operator==(nullptr_t, const _type& y)
1334 {
1335 return y == 0;
1336 }
1337 template<typename _type>
1338 YB_ATTR_nodiscard YB_STATELESS friend yconstfn bool
1339 operator==(const _type& x, nullptr_t)
1340 {
1341 return x == 0;
1342 }
1343
1344 template<typename _type>
1345 YB_ATTR_nodiscard YB_STATELESS friend yconstfn bool
1346 operator!=(nullptr_t, const _type& y)
1347 {
1348 return !(y == 0);
1349 }
1350 template<typename _type>
1351 YB_ATTR_nodiscard YB_STATELESS friend yconstfn bool
1352 operator!=(const _type& x, nullptr_t)
1353 {
1354 return !(x == 0);
1355 }
1357
1359 template<typename _type>
1360 yconstfn
1361 operator _type*() const ynothrow
1362 {
1363 return 0;
1364 }
1365
1367 template<class _tClass, typename _type>
1368 yconstfn
1369 operator _type _tClass::*() const ynothrow
1370 {
1371 return 0;
1372 }
1374 } nullptr = {};
1375 #endif
1376
1377
1422 template<typename...>
1423 struct empty_base
1424 {};
1425
1431 struct raw_tag
1432 {};
1433
1434
1440 template<bool _bMemObjPtr, bool _bNoExcept, class _type>
1441 class offsetof_check
1442 {
1443 static_assert(std::is_class<_type>::value, "Non class type found.");
1444 static_assert(std::is_standard_layout<_type>::value,
1445 "Non standard layout type found.");
1446 static_assert(_bMemObjPtr, "Non-static member object violation found.");
1447 static_assert(_bNoExcept, "Exception guarantee violation found.");
1448 };
1449
1450
1458 #define yunused(...) static_cast<void>(__VA_ARGS__)
1459
1471 #if __has_builtin(__builtin_offsetof) || YB_IMPL_GNUCPP >= 40000 \
1472 || YB_IMPL_CLANGPP >= 20200
1473 # define yoffsetof(_type, _member) \
1474 (decltype(sizeof(ystdex::offsetof_check< \
1475 std::is_member_object_pointer<decltype(&_type::_member)>::value, \
1476 ynoexcept(__builtin_offsetof(_type, _member)), _type>))( \
1477 __builtin_offsetof(_type, _member)))
1478 #else
1479 # define yoffsetof(_type, _member) \
1480 (decltype(sizeof(ystdex::offsetof_check<std::is_member_object_pointer< \
1481 decltype(&_type::_member)>::value, ynoexcept(offsetof(_type, _member)), \
1482 _type>))(offsetof(_type, _member)))
1483 #endif
1484
1508 #define yforward(_expr) std::forward<decltype(_expr)>(_expr)
1509
1515 template<typename _type, typename... _tParams>
1516 yconstfn auto
1517 unsequenced(_type&& arg, _tParams&&...) ynothrow -> decltype(yforward(arg))
1518 {
1519 return yforward(arg);
1520 }
1521
1535 #define yunseq ystdex::unsequenced
1536
1537 } // namespace ystdex;
1538
1539 #endif
1540
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
ystdex::nullptr_t::operator!=
friend bool operator!=(const _type &x, nullptr_t)
Definition: ydef.h:1352
x
const EncapsulationBase & x
Definition: NPLA1Forms.cpp:1536
ystdex::empty_base
空基类模板。
Definition: ydef.h:1424
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
ystdex::offsetof_check
成员偏移计算静态类型检查。
Definition: ydef.h:1442
ystdex::nullptr_t::operator!=
friend bool operator!=(nullptr_t, const _type &y)
Definition: ydef.h:1346
platform::size_t
YB_ATTR_nodiscard YF_API size_t
Definition: FileIO.h:1345
ystdex::nullptr_t
空指针类。
Definition: ydef.h:1321
ystdex::nullptr_t::operator==
friend bool operator==(const _type &x, nullptr_t)
Definition: ydef.h:1339
ystdex::nullptr_t::operator==
friend bool operator==(nullptr_t, const _type &y)
重载关系操作符。
Definition: ydef.h:1333
ystdex::unsequenced
auto unsequenced(_type &&arg, _tParams &&...) -> decltype(std::forward< decltype(arg)>(arg))
无序列依赖表达式组求值实现。
Definition: ydef.h:1517
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
ystdex::raw_tag
直接构造类型（直接构造重载用）。
Definition: ydef.h:1432
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::nullptr_t::operator&
void operator&() const =delete
禁止取 nullptr 的指针。
ystdex::octet
void octet
Definition: ydef.h:1294
ystdex::byte
unsigned char byte
字节类型。
Definition: ydef.h:1283
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073