Skip to content

Commit 843aa3f

Browse files
committed
* improvements in compiler function detection.
1 parent c9d0ac0 commit 843aa3f

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

include/fast_float/constexpr_feature_detect.h

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,32 @@
77
#endif
88
#endif
99

10-
// Testing for https://wg21.link/N3652, adopted in C++14
11-
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304
10+
// C++14 constexpr
11+
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304L
12+
#define FASTFLOAT_CONSTEXPR14 constexpr
13+
#elif __cplusplus >= 201402L
14+
#define FASTFLOAT_CONSTEXPR14 constexpr
15+
#elif defined(_MSC_VER) && _MSC_VER >= 1910 && _MSVC_LANG >= 201402L
1216
#define FASTFLOAT_CONSTEXPR14 constexpr
1317
#else
1418
#define FASTFLOAT_CONSTEXPR14
1519
#endif
1620

21+
// C++14 variable templates
22+
#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304L
23+
#define FASTFLOAT_HAS_VARIABLE_TEMPLATES 1
24+
#elif __cplusplus >= 201402L
25+
#define FASTFLOAT_HAS_VARIABLE_TEMPLATES 1
26+
#elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918L && \
27+
_MSVC_LANG >= 201402L
28+
#define FASTFLOAT_HAS_VARIABLE_TEMPLATES 1
29+
#else
30+
#define FASTFLOAT_HAS_VARIABLE_TEMPLATES 0
31+
#endif
32+
33+
// C++20 std::bit_cast
1734
#if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L
35+
#include <bit>
1836
#define FASTFLOAT_HAS_BIT_CAST 1
1937
#else
2038
#define FASTFLOAT_HAS_BIT_CAST 0
@@ -35,12 +53,39 @@
3553
#define FASTFLOAT_HAS_BYTESWAP 0
3654
#endif
3755

56+
// C++17 if constexpr
3857
#if defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
3958
#define FASTFLOAT_IF_CONSTEXPR17(x) if constexpr (x)
59+
#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L
60+
#define FASTFLOAT_IF_CONSTEXPR17(x) if constexpr (x)
61+
#elif __cplusplus >= 201703L
62+
#define FASTFLOAT_IF_CONSTEXPR17(x) if constexpr (x)
63+
#elif defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L
64+
#define FASTFLOAT_IF_CONSTEXPR17(x) if constexpr (x)
4065
#else
4166
#define FASTFLOAT_IF_CONSTEXPR17(x) if (x)
4267
#endif
4368

69+
// C++17 inline variables
70+
#if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L
71+
#define FASTFLOAT_INLINE_VARIABLE inline constexpr
72+
#elif __cplusplus >= 201703L
73+
#define FASTFLOAT_INLINE_VARIABLE inline constexpr
74+
#elif defined(_MSC_VER) && _MSC_VER >= 1912 && _MSVC_LANG >= 201703L
75+
#define FASTFLOAT_INLINE_VARIABLE inline constexpr
76+
#else
77+
#define FASTFLOAT_INLINE_VARIABLE static constexpr
78+
#endif
79+
80+
#if defined(__cpp_lib_is_constant_evaluated) && \
81+
__cpp_lib_is_constant_evaluated >= 201811L
82+
#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 1
83+
#define FASTFLOAT_CONSTEVAL consteval
84+
#else
85+
#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 0
86+
#define FASTFLOAT_CONSTEVAL FASTFLOAT_CONSTEXPR14
87+
#endif
88+
4489
// Testing for relevant C++20 constexpr library features
4590
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED && FASTFLOAT_HAS_BIT_CAST && \
4691
defined(__cpp_lib_constexpr_algorithms) && \
@@ -58,6 +103,12 @@
58103
#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 1
59104
#endif
60105

106+
#if defined(__has_builtin)
107+
#define FASTFLOAT_HAS_BUILTIN(x) __has_builtin(x)
108+
#else
109+
#define FASTFLOAT_HAS_BUILTIN(x) false
110+
#endif
111+
61112
// For support attribute [[assume]] is declared in P1774
62113
#if defined(__cpp_attrubute_assume)
63114
#define FASTFLOAT_ASSUME(expr) [[assume(expr)]]

0 commit comments

Comments
 (0)