From d34d0d7405f0c913d9ed4907587402c8b6143c55 Mon Sep 17 00:00:00 2001 From: Lenard Szolnoki Date: Sun, 12 Mar 2023 10:30:49 +0000 Subject: [PATCH] Fix amalgamate.ph and add header for constexpr macros --- include/fast_float/constexpr_feature_detect.h | 40 +++++++++++++++++++ include/fast_float/fast_float.h | 2 +- include/fast_float/float_common.h | 35 +--------------- script/amalgamate.py | 5 ++- 4 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 include/fast_float/constexpr_feature_detect.h diff --git a/include/fast_float/constexpr_feature_detect.h b/include/fast_float/constexpr_feature_detect.h new file mode 100644 index 0000000..9ec8611 --- /dev/null +++ b/include/fast_float/constexpr_feature_detect.h @@ -0,0 +1,40 @@ +#ifndef FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H +#define FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H + +#ifdef __has_include +#if __has_include() +#include +#endif +#endif + +// Testing for https://wg21.link/N3652, adopted in C++14 +#if __cpp_constexpr >= 201304 +#define FASTFLOAT_CONSTEXPR14 constexpr +#else +#define FASTFLOAT_CONSTEXPR14 +#endif + +#if __cpp_lib_bit_cast >= 201806L +#define FASTFLOAT_HAS_BIT_CAST 1 +#else +#define FASTFLOAT_HAS_BIT_CAST 0 +#endif + +#if __cpp_lib_is_constant_evaluated >= 201811L +#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 1 +#else +#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 0 +#endif + +// Testing for relevant C++20 constexpr library features +#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED \ + && FASTFLOAT_HAS_BIT_CAST \ + && __cpp_lib_constexpr_algorithms >= 201806L /*For std::copy and std::fill*/ +#define FASTFLOAT_CONSTEXPR20 constexpr +#define FASTFLOAT_IS_CONSTEXPR 1 +#else +#define FASTFLOAT_CONSTEXPR20 +#define FASTFLOAT_IS_CONSTEXPR 0 +#endif + +#endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H diff --git a/include/fast_float/fast_float.h b/include/fast_float/fast_float.h index 12ec693..65704da 100644 --- a/include/fast_float/fast_float.h +++ b/include/fast_float/fast_float.h @@ -3,7 +3,7 @@ #include -#include "float_common.h" +#include "constexpr_feature_detect.h" namespace fast_float { enum chars_format { diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 468458d..c878486 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -7,23 +7,8 @@ #include #include -#ifdef __has_include -#if __has_include() -#include -#endif -#endif - -#if __cpp_lib_bit_cast >= 201806L +#if FASTFLOAT_HAS_BIT_CAST #include -#define FASTFLOAT_HAS_BIT_CAST 1 -#else -#define FASTFLOAT_HAS_BIT_CAST 0 -#endif - -#if __cpp_lib_is_constant_evaluated >= 201811L -#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 1 -#else -#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 0 #endif #if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) \ @@ -110,24 +95,6 @@ // rust style `try!()` macro, or `?` operator #define FASTFLOAT_TRY(x) { if (!(x)) return false; } -// Testing for https://wg21.link/N3652, adopted in C++14 -#if __cpp_constexpr >= 201304 -#define FASTFLOAT_CONSTEXPR14 constexpr -#else -#define FASTFLOAT_CONSTEXPR14 -#endif - -// Testing for relevant C++20 constexpr library features -#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED \ - && FASTFLOAT_HAS_BIT_CAST \ - && __cpp_lib_constexpr_algorithms >= 201806L /*For std::copy and std::fill*/ -#define FASTFLOAT_CONSTEXPR20 constexpr -#define FASTFLOAT_IS_CONSTEXPR 1 -#else -#define FASTFLOAT_CONSTEXPR20 -#define FASTFLOAT_IS_CONSTEXPR 0 -#endif - namespace fast_float { fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() { diff --git a/script/amalgamate.py b/script/amalgamate.py index 7d4e4aa..7ef44d4 100644 --- a/script/amalgamate.py +++ b/script/amalgamate.py @@ -31,7 +31,7 @@ for filename in ['LICENSE-MIT', 'LICENSE-APACHE']: processed_files[filename] = text # code -for filename in [ 'float_common.h', 'fast_float.h', 'ascii_number.h', +for filename in [ 'constexpr_feature_detect.h', 'fast_float.h', 'float_common.h', 'ascii_number.h', 'fast_table.h', 'decimal_to_binary.h', 'bigint.h', 'ascii_number.h', 'digit_comparison.h', 'parse_number.h']: with open('include/fast_float/' + filename, encoding='utf8') as f: @@ -75,7 +75,8 @@ def license_content(license_arg): text = ''.join([ processed_files['AUTHORS'], processed_files['CONTRIBUTORS'], *license_content(args.license), - processed_files['float_common.h'], processed_files['fast_float.h'], + processed_files['constexpr_feature_detect.h'], + processed_files['fast_float.h'], processed_files['float_common.h'], processed_files['ascii_number.h'], processed_files['fast_table.h'], processed_files['decimal_to_binary.h'], processed_files['bigint.h'], processed_files['ascii_number.h'], processed_files['digit_comparison.h'],