NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
c++config.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_CONFIG_CPPCONFIG_HPP__
2#define NEFORCE_CORE_CONFIG_CPPCONFIG_HPP__
3
21
22#include <cassert>
23#include "NeForce/core/config/version.hpp"
24
30
31#if defined(WIN32) || defined(_WIN32) || defined(_M_X86) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
32
37# define NEFORCE_PLATFORM_WINDOWS 1
38
43# define NEFORCE_PLATFORM_WINDOWS32 1
44
45# if defined(WIN64) || defined(_WIN64) || defined(_M_X64) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
50# define NEFORCE_PLATFORM_WINDOWS64 1
51# endif
52#endif
53
54#if defined(__linux__) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
59# define NEFORCE_PLATFORM_LINUX 1
60
61# if (__WORDSIZE == 32) || (__SIZEOF_POINTER__ == 4) || defined(NEFORCE_PLATFORM_LINUX64) || \
62 defined(NEXUSFORCE_ENABLE_DOXYGEN)
67# define NEFORCE_PLATFORM_LINUX32 1
68# endif
69
70# if (__WORDSIZE == 64) || (__SIZEOF_POINTER__ == 8) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
75# define NEFORCE_PLATFORM_LINUX64 1
76# endif
77#endif
78
79#if !(defined(NEFORCE_PLATFORM_WINDOWS) || defined(NEFORCE_PLATFORM_LINUX))
80# error "NeForce: 不支持的操作系统"
81#endif
82
83
84#ifdef NEFORCE_PLATFORM_WINDOWS
85
86# ifndef WIN32_LEAN_AND_MEAN
87# define WIN32_LEAN_AND_MEAN
88# endif
89
90# ifndef NOMINMAX
91# define NOMINMAX
92# endif
93
94# ifdef bool
95# undef bool
96# endif
97
98# ifdef true
99# undef true
100# endif
101
102# ifdef false
103# undef false
104# endif
105
106# ifdef max
107# undef max
108# endif
109
110# ifdef min
111# undef min
112# endif
113
114#endif
115 // PlatformDetection
117
123
124#if defined(__clang__) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
129# define NEFORCE_COMPILER_CLANG 1
130#endif
131
132#if defined(__GNUC__) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
137# define NEFORCE_COMPILER_GNUC 1
138#endif
139
140#if defined(_MSC_VER) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
145# define NEFORCE_COMPILER_MSVC 1
146
147# if defined(NEFORCE_COMPILER_CLANG) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
148# define NEFORCE_COMPILER_CLANG_CL 1
149# endif
150#endif
151
152#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
157# define NEFORCE_COMPILER_GCC 1
158#endif
159
160#if defined(__MINGW32__) || defined(__MINGW64__) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
165# define NEFORCE_COMPILER_MINGW 1
166# if defined(NEFORCE_COMPILER_CLANG) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
171# define NEFORCE_COMPILER_LLVM_MINGW 1
172# endif
173#endif
174
175#if !(defined(NEFORCE_COMPILER_GNUC) || defined(NEFORCE_COMPILER_MSVC))
176# error "NeForce: 不支持的编译器"
177#endif
178
179#ifdef __clang_analyzer__
180# define NEFORCE_ANALYZER_CLANG 1
181#endif
182 // CompilerDetection
184
190
191#if defined(NEFORCE_COMPILER_MSVC)
196# define NEFORCE_API_EXPORT_DLL __declspec(dllexport)
201# define NEFORCE_API_IMPORT_DLL __declspec(dllimport)
202#endif
203
204#if defined(NEFORCE_COMPILER_GNUC)
209# define NEFORCE_API_EXPORT
210#endif
211
212#if defined(NEFORCE_COMPILER_GNUC)
213# define NEFORCE_API NEFORCE_API_EXPORT
214#else
215# if defined(NEFORCE_DLLEXPORTS)
216# define NEFORCE_API NEFORCE_API_EXPORT_DLL
217# else
218# define NEFORCE_API NEFORCE_API_IMPORT_DLL
219# endif
220#endif
221 // APIImpExpSpec
223
229
230#if defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || \
231 defined(__I86__) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
232# define NEFORCE_ARCH_X86_32 1
233#endif
234
235#if defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(__amd64__) || defined(__amd64) || \
236 defined(_M_AMD64) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
237# define NEFORCE_ARCH_X86_64 1
238#endif
239
240#if defined(NEFORCE_ARCH_X86_32) || defined(NEFORCE_ARCH_X86_64)
241# define NEFORCE_ARCH_X86 1
242#endif
243
244
245#if (defined(__arm__) || defined(__arm) || defined(_ARM_) || defined(_M_ARM) || defined(__TARGET_ARCH_ARM)) && \
246 !defined(__aarch64__) && !defined(_M_ARM64) && !defined(__ARM64_ARCH_8__)
247# define NEFORCE_ARCH_ARM32 1
248#endif
249
250#if defined(__aarch64__) || defined(__aarch64) || defined(_M_ARM64) || defined(__ARM64_ARCH_8__) || \
251 defined(__ARM_ARCH_ISA_A64) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
252# define NEFORCE_ARCH_AARCH64 1
253#endif
254
255#if defined(NEFORCE_ARCH_ARM32) || defined(NEFORCE_ARCH_AARCH64)
256# define NEFORCE_ARCH_ARM 1
257#endif
258
259
260#if defined(__riscv) || defined(__riscv__) || defined(riscv) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
261# define NEFORCE_ARCH_RISCV 1
262# if __riscv_xlen == 32 || defined(NEXUSFORCE_ENABLE_DOXYGEN)
263# define NEFORCE_ARCH_RISCV32 1
264# endif
265# if __riscv_xlen == 64 || defined(NEXUSFORCE_ENABLE_DOXYGEN)
266# define NEFORCE_ARCH_RISCV64 1
267# endif
268#endif
269
270
271#if defined(__loongarch__) || defined(__loongarch) || defined(__loongarch32) || defined(__loongarch64) || \
272 defined(_LOONGARCH_SIM) || defined(_LOONGARCH) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
273# define NEFORCE_ARCH_LOONGARCH 1
274# if defined(__loongarch32) || _LOONGARCH_SIM == _ABILP32_SIM || defined(NEXUSFORCE_ENABLE_DOXYGEN)
275# define NEFORCE_ARCH_LOONGARCH32 1
276# endif
277# if defined(__loongarch64) || _LOONGARCH_SIM == _ABILP64_SIM || defined(NEXUSFORCE_ENABLE_DOXYGEN)
278# define NEFORCE_ARCH_LOONGARCH64 1
279# endif
280#endif
281
282#if !(defined(NEFORCE_ARCH_X86) || defined(NEFORCE_ARCH_ARM) || defined(NEFORCE_ARCH_RISCV) || \
283 defined(NEFORCE_ARCH_LOONGARCH))
284# error "NeForce: 不支持的指令集"
285#endif
286 // ArchitectureDetection
288
294
295#if defined(NEFORCE_ARCH_X86)
296# if defined(__SSE2__) || defined(_M_X64) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
297# define NEFORCE_SIMD_SSE2 1
298# endif
299# if defined(__AVX__) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
300# define NEFORCE_SIMD_AVX 1
301# endif
302# if defined(__AVX2__) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
303# define NEFORCE_SIMD_AVX2 1
304# endif
305# if defined(__AVX512F__) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
306# define NEFORCE_SIMD_AVX512F 1
307# endif
308# if (defined(NEFORCE_COMPILER_MSVC) && (defined(__AVX__) || defined(__AVX2__) || defined(__AVX512F__))) || \
309 defined(__SSSE3__) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
310# define NEFORCE_SIMD_SSSE3 1
311# endif
312#elif (defined(NEFORCE_ARCH_ARM) && defined(__ARM_NEON)) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
313# define NEFORCE_SIMD_NEON 1
314#endif
315
316#if defined(NEFORCE_SIMD_SSE2) || defined(NEFORCE_SIMD_AVX2) || defined(NEFORCE_SIMD_NEON)
317# define NEFORCE_SUPPORT_SIMD 1
318#endif
319 // SimdDetection
321
327
328#if defined(NEFORCE_ARCH_X86)
329# if defined(__AES__) || defined(_MSC_VER) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
330# define NEFORCE_SIMD_AES_NI 1
331# endif
332#endif
333#if defined(NEFORCE_ARCH_ARM)
334# if defined(__ARM_FEATURE_AES) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
335# define NEFORCE_SIMD_AES_ARM 1
336# endif
337#endif
338 // AesniDetection
340
346
347#if defined(NEFORCE_ARCH_X86_64) || defined(NEFORCE_ARCH_AARCH64) || defined(NEFORCE_ARCH_RISCV64) || \
348 defined(NEFORCE_ARCH_LOONGARCH64) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
353# define NEFORCE_ARCH_BITS_64 1
354#endif
355#if defined(NEFORCE_ARCH_X86_32) || defined(NEFORCE_ARCH_ARM32) || defined(NEFORCE_ARCH_RISCV32) || \
356 defined(NEFORCE_ARCH_LOONGARCH32) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
361# define NEFORCE_ARCH_BITS_32 1
362#endif
363
364#if !(defined(NEFORCE_ARCH_BITS_64) || defined(NEFORCE_ARCH_BITS_32))
365# error "NeForce: 不支持的位宽"
366#endif
367 // DataBusWidth
369
370
371#if defined(NEFORCE_ARCH_X86) && defined(NEFORCE_USING_INTEL_TSX)
372# define NEFORCE_SUPPORT_INTEL_TSX 1
373#endif
374
375#ifdef NEFORCE_ARCH_BITS_64
376# define NEFORCE_SUPPORT_INTRINSIC_INT128 1
377#endif
378
379
385
386#if (__cplusplus >= 202100L) || (_MSVC_LANG >= 202100L)
391# define NEFORCE_STANDARD_23 1
392#endif
393#if (__cplusplus >= 202002L) || defined(NEFORCE_STANDARD_23) || (_MSVC_LANG >= 202002L)
398# define NEFORCE_STANDARD_20 1
399#endif
400#if (__cplusplus >= 201703L) || defined(NEFORCE_STANDARD_20) || (_MSVC_LANG >= 201703L)
405# define NEFORCE_STANDARD_17 1
406#endif
407#if (__cplusplus >= 201402L) || defined(NEFORCE_STANDARD_17) || (_MSVC_LANG >= 201402L)
412# define NEFORCE_STANDARD_14 1
413#endif
414#if (__cplusplus >= 201103L) || defined(NEFORCE_STANDARD_14) || (_MSVC_LANG >= 201103L)
419# define NEFORCE_STANDARD_11 1
420#endif
421#if (__cplusplus >= 199711L) || defined(NEFORCE_STANDARD_11) || (_MSVC_LANG >= 199711L)
426# define NEFORCE_STANDARD_98 1
427#endif
428 // CxxStandardDetection
430
431
432#define __NEFORCE_GLOBAL_NAMESPACE__ neforce
433#define NEFORCE_BEGIN_NAMESPACE__ namespace __NEFORCE_GLOBAL_NAMESPACE__ {
434#define NEFORCE_END_NAMESPACE__ }
435#define _NEFORCE __NEFORCE_GLOBAL_NAMESPACE__ ::
436
437#define __NEFORCE_INNER_NAMESPACE__ inner
438#define NEFORCE_BEGIN_INNER__ namespace __NEFORCE_INNER_NAMESPACE__ {
439#define NEFORCE_END_INNER__ }
440
441#define __NEFORCE_SIMD_NAMESPACE__ simd
442#define NEFORCE_BEGIN_SIMD__ namespace __NEFORCE_SIMD_NAMESPACE__ {
443#define NEFORCE_END_SIMD__ }
444
445#define __NEFORCE_CONSTANTS_NAMESPACE__ constants
446#define NEFORCE_BEGIN_CONSTANTS__ namespace __NEFORCE_CONSTANTS_NAMESPACE__ {
447#define NEFORCE_END_CONSTANTS__ }
448
449#define __NEFORCE_THIS_THREAD_NAMESPACE__ this_thread
450#define NEFORCE_BEGIN_THIS_THREAD__ namespace __NEFORCE_THIS_THREAD_NAMESPACE__ {
451#define NEFORCE_END_THIS_THREAD__ }
452
453#define __NEFORCE_RANGES_NAMESPACE__ ranges
454#define NEFORCE_BEGIN_RANGES__ namespace __NEFORCE_RANGES_NAMESPACE__ {
455#define NEFORCE_END_RANGES__ }
456
457#define __NEFORCE_RANGES_VIEWS_NAMESPACE__ views
458#define NEFORCE_BEGIN_RANGES_VIEWS__ namespace __NEFORCE_RANGES_VIEWS_NAMESPACE__ {
459#define NEFORCE_END_RANGES_VIEWS__ }
460
461#define __NEFORCE_LITERALS_NAMESPACE__ literals
462#define NEFORCE_BEGIN_LITERALS__ inline namespace __NEFORCE_LITERALS_NAMESPACE__ {
463#define NEFORCE_END_LITERALS__ }
464
465#define __NEFORCE_REFLECT_NAMESPACE__ reflect
466#define NEFORCE_BEGIN_REFLECT__ namespace __NEFORCE_REFLECT_NAMESPACE__ {
467#define NEFORCE_END_REFLECT__ }
468
469#define __NEFORCE_SERIALIZE_NAMESPACE__ serialize
470#define NEFORCE_BEGIN_SERIALIZE__ namespace __NEFORCE_SERIALIZE_NAMESPACE__ {
471#define NEFORCE_END_SERIALIZE__ }
472
473#define __NEFORCE_HTTP_NAMESPACE__ http
474#define NEFORCE_BEGIN_HTTP__ namespace __NEFORCE_HTTP_NAMESPACE__ {
475#define NEFORCE_END_HTTP__ }
476
477#define __NEFORCE_TUI_NAMESPACE__ tui
478#define NEFORCE_BEGIN_TUI__ namespace __NEFORCE_TUI_NAMESPACE__ {
479#define NEFORCE_END_TUI__ }
480
481#define __NEFORCE_COMPONENTS_NAMESPACE__ components
482#define NEFORCE_BEGIN_COMPONENTS__ namespace __NEFORCE_COMPONENTS_NAMESPACE__ {
483#define NEFORCE_END_COMPONENTS__ }
484
485
486#ifdef NEFORCE_STANDARD_11
487# define NEFORCE_CONSTEXPR11 constexpr
488#else
489# define NEFORCE_CONSTEXPR11 inline
490#endif // NEFORCE_STANDARD_11
491
492#ifdef NEFORCE_STANDARD_14
493# define NEFORCE_CONSTEXPR14 constexpr
494#else
495# define NEFORCE_CONSTEXPR14 inline
496#endif // NEFORCE_STANDARD_14
497
498#ifdef NEFORCE_STANDARD_17
499# define NEFORCE_CONSTEXPR17 constexpr
500# define NEFORCE_INLINE17 inline
501#else
502# define NEFORCE_CONSTEXPR17 inline
503# define NEFORCE_INLINE17
504#endif // NEFORCE_STANDARD_17
505
506#ifdef NEFORCE_STANDARD_20
507# define NEFORCE_CONSTEXPR20 constexpr
508# define NEFORCE_CONSTEVAL20 consteval
509#else
510# define NEFORCE_CONSTEXPR20 inline
511# define NEFORCE_CONSTEVAL20 constexpr
512#endif // NEFORCE_STANDARD_20
513
514#ifdef NEFORCE_STANDARD_23
515# define NEFORCE_CONSTEXPR23 constexpr
516#else
517# define NEFORCE_CONSTEXPR23 inline
518#endif // NEFORCE_STANDARD_23
519
520
521#ifdef NEFORCE_STANDARD_17
522# define NEFORCE_IF_CONSTEXPR if constexpr
523#else
524# define NEFORCE_IF_CONSTEXPR if
525#endif
526
527
528#ifdef NEFORCE_STANDARD_17
529# define NEFORCE_NODISCARD [[nodiscard]]
530
531# define NEFORCE_ALLOC_NODISCARD [[nodiscard("discard the return of allocators will cause memory leaks.")]]
532#else
533# define NEFORCE_NODISCARD
534
535# define NEFORCE_ALLOC_NODISCARD
536#endif
537
538
539#ifdef NEFORCE_COMPILER_GNUC
540# define NEFORCE_ALWAYS_INLINE __attribute__((always_inline))
541# define NEFORCE_ALWAYS_INLINE_INLINE NEFORCE_ALWAYS_INLINE inline
542#elif defined(NEFORCE_COMPILER_MSVC)
543# define NEFORCE_ALWAYS_INLINE __forceinline
544# define NEFORCE_ALWAYS_INLINE_INLINE NEFORCE_ALWAYS_INLINE
545#else
546# define NEFORCE_ALWAYS_INLINE inline
547# define NEFORCE_ALWAYS_INLINE_INLINE inline
548#endif
549
550
551#ifdef NEFORCE_COMPILER_GNUC
552# define NEFORCE_UNUSED __attribute__((unused))
553#else
554# define NEFORCE_UNUSED
555#endif
556
557
558#ifdef NEFORCE_STANDARD_17
559# define NEFORCE_UNLIKELY [[unlikely]]
560#else
561# define NEFORCE_UNLIKELY
562#endif
563
564
565#ifdef NEFORCE_STANDARD_20
566# define NEFORCE_LIKELY [[likely]]
567#else
568# define NEFORCE_LIKELY
569#endif
570
571
572#if defined(NEFORCE_STANDARD_11)
573# define NEFORCE_NORETURN [[noreturn]]
574#elif defined(NEFORCE_COMPILER_GNUC)
575# define NEFORCE_NORETURN __attribute__((noreturn))
576#elif defined(NEFORCE_COMPILER_MSVC)
577# define NEFORCE_NORETURN __declspec(noreturn)
578#else
579# define NEFORCE_NORETURN
580#endif
581
582
583#ifndef NEFORCE_COMPILER_GNUC
584# define NEFORCE_PURE_FUNCTION
585# define NEFORCE_CONST_FUNCTION
586#else
587# define NEFORCE_PURE_FUNCTION __attribute__((__pure__))
588# define NEFORCE_CONST_FUNCTION __attribute__((__const__))
589#endif
590
591
592#ifdef NEFORCE_STANDARD_14
593# define NEFORCE_DEPRECATED [[deprecated]]
594# define NEFORCE_DEPRECATED_FOR(MSG) [[deprecated(MSG)]]
595#else
596# define NEFORCE_DEPRECATED
597# define NEFORCE_DEPRECATED_FOR(MSG)
598#endif
599
600
601#if defined(NEFORCE_COMPILER_GNUC)
602# define NEFORCE_NOVTABLE __attribute__((novtable))
603#elif defined(NEFORCE_COMPILER_MSVC)
604# define NEFORCE_NOVTABLE __declspec(novtable)
605#else
606# define NEFORCE_NOVTABLE
607#endif
608
609
610#if defined(NEFORCE_COMPILER_GNUC)
611# define NEFORCE_ALLOC_OPTIMIZE NEFORCE_ALWAYS_INLINE
612#elif defined(NEFORCE_COMPILER_MSVC)
613# define NEFORCE_ALLOC_OPTIMIZE __declspec(allocator)
614#else
615# define NEFORCE_ALLOC_OPTIMIZE
616#endif
617
618
619#if defined(NEFORCE_COMPILER_GNUC)
620# define NEFORCE_RESTRICT __restrict__
621#else
622# define NEFORCE_RESTRICT __restrict
623#endif
624
625
633
634#ifdef NEFORCE_STANDARD_20
639# define NEFORCE_MACRO_RANGE_UNICODE_CHARS(MAC) \
640 MAC(char8_t) \
641 MAC(char16_t) \
642 MAC(char32_t)
643#else
644# define NEFORCE_MACRO_RANGE_UNICODE_CHARS(MAC) \
645 MAC(char16_t) \
646 MAC(char32_t)
647#endif
648
653#define NEFORCE_MACRO_RANGE_CHARS(MAC) \
654 MAC(char) \
655 MAC(wchar_t) \
656 NEFORCE_MACRO_RANGE_UNICODE_CHARS(MAC)
657
662#define NEFORCE_MACRO_RANGE_SIGNED_INT(MAC) \
663 MAC(signed char) \
664 MAC(short) \
665 MAC(int) \
666 MAC(long) \
667 MAC(long long)
668
673#define NEFORCE_MACRO_RANGE_UNSIGNED_INT(MAC) \
674 MAC(unsigned char) \
675 MAC(unsigned short) \
676 MAC(unsigned int) \
677 MAC(unsigned long) \
678 MAC(unsigned long long)
679
684#define NEFORCE_MACRO_RANGE_INT(MAC) \
685 NEFORCE_MACRO_RANGE_SIGNED_INT(MAC) \
686 NEFORCE_MACRO_RANGE_UNSIGNED_INT(MAC)
687
692#define NEFORCE_MACRO_RANGE_FLOAT(MAC) \
693 MAC(float) \
694 MAC(double) \
695 MAC(long double)
696
701#define NEFORCE_MACRO_RANGE_ARITHMETIC(MAC) \
702 NEFORCE_MACRO_RANGE_CHARS(MAC) \
703 NEFORCE_MACRO_RANGE_INT(MAC) \
704 NEFORCE_MACRO_RANGE_FLOAT(MAC)
705
710#define NEFORCE_MACRO_RANGES_CV(MAC) \
711 MAC(const) \
712 MAC(volatile) \
713 MAC(const volatile)
714
719#define NEFORCE_MACRO_RANGES_CV_REF(MAC) \
720 MAC(&) \
721 MAC(const&) \
722 MAC(volatile&) \
723 MAC(const volatile&) \
724 MAC(&&) \
725 MAC(const&&) \
726 MAC(volatile&&) \
727 MAC(const volatile&&)
728
733#define NEFORCE_MACRO_RANGES_CV_REF_NOEXCEPT(MAC) \
734 MAC(noexcept) \
735 MAC(const noexcept) \
736 MAC(volatile noexcept) \
737 MAC(const volatile noexcept) \
738 MAC(& noexcept) \
739 MAC(const& noexcept) \
740 MAC(volatile& noexcept) \
741 MAC(const volatile& noexcept) \
742 MAC(&& noexcept) \
743 MAC(const&& noexcept) \
744 MAC(volatile&& noexcept) \
745 MAC(const volatile&& noexcept)
746 // TypeRangeMacros
748
749#endif // NEFORCE_CORE_CONFIG_CPPCONFIG_HPP__