cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
platforms.hpp
Go to the documentation of this file.
1#pragma once
2
12#if defined(_MSC_VER)
13# define CPP_TOOLBOX_COMPILER_MSVC
14#elif defined(__clang__)
15# define CPP_TOOLBOX_COMPILER_CLANG
16#elif defined(__GNUC__)
17# define CPP_TOOLBOX_COMPILER_GCC
18#endif
19
32#if defined(_WIN32) || defined(_WIN64)
33# define CPP_TOOLBOX_PLATFORM_WINDOWS
34#elif defined(__linux__) || defined(__linux)
35# define CPP_TOOLBOX_PLATFORM_LINUX
36#elif defined(__APPLE__) || defined(__MACH__)
37# define CPP_TOOLBOX_PLATFORM_MACOS
38#elif defined(__FreeBSD__) || defined(__FreeBSD)
39# define CPP_TOOLBOX_PLATFORM_FREEBSD
40#elif defined(__NetBSD__) || defined(__NetBSD)
41# define CPP_TOOLBOX_PLATFORM_NETBSD
42// Android
43#elif defined(__ANDROID__) || defined(_ANDROID)
44# define CPP_TOOLBOX_PLATFORM_ANDROID
45#elif defined(__QNX__) || defined(_QNX)
46# define CPP_TOOLBOX_PLATFORM_QNX
47#endif
48
60#if defined(__x86_64__) || defined(__amd64__) || defined(__amd64) \
61 || defined(_M_X64)
62# define CPP_TOOLBOX_ARCH_X86_64
63#elif defined(__i386__) || defined(__i386) || defined(_M_IX86)
64# define CPP_TOOLBOX_ARCH_X86
65#elif defined(__aarch64__) || defined(__arm64__) || defined(__arm64) \
66 || defined(_M_ARM64)
67# define CPP_TOOLBOX_ARCH_ARM64
68#elif defined(__arm__) || defined(__arm) || defined(_M_ARM)
69# define CPP_TOOLBOX_ARCH_ARM
70#elif defined(__riscv__) || defined(__riscv) || defined(_M_RISCV)
71# define CPP_TOOLBOX_ARCH_RISCV
72#elif defined(__loongarch__) || defined(__loongarch) || defined(_M_LOONGARCH)
73# define CPP_TOOLBOX_ARCH_LOONGARCH
74#endif
75
89#define CPP_VERSION_STR(year, month) #year #month "L"
90
104#define CPP_VERSION_TO_INT(year, month) year##month##L
105
109#if defined(__cplusplus)
110# define CPP_TOOLBOX_CXX_STANDARD __cplusplus
111#endif
112
116#define CPP_11 CPP_VERSION_TO_INT(201, 103)
117#define CPP_14 CPP_VERSION_TO_INT(201, 402)
118#define CPP_17 CPP_VERSION_TO_INT(201, 703)
119#define CPP_20 CPP_VERSION_TO_INT(202, 002)
120
131constexpr const char* get_cpp_version()
132{
133#if __cplusplus >= CPP_20
134 return "C++20";
135#elif __cplusplus >= CPP_17
136 return "C++17";
137#elif __cplusplus >= CPP_14
138 return "C++14";
139#elif __cplusplus >= CPP_11
140 return "C++11";
141#else
142 return "Pre-C++11";
143#endif
144}
145
154#define CPP_TOOLBOX_CXX_LARGE_THAN_17(Content) \
155 static_assert(__cplusplus >= CPP_17, Content)
156
160#define CPP_TOOLBOX_CXX_VERSION get_cpp_version()
constexpr const char * get_cpp_version()
获取C++版本字符串 / Get C++ version as string
Definition platforms.hpp:131