From 8e5159513929c508eaadfb82fa124ea1929a1603 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 15 Mar 2023 18:54:46 -0700 Subject: [PATCH] Fix compiler errors under C++14 --- include/boost/charconv/detail/bit_layouts.hpp | 20 ---------------- include/boost/charconv/detail/config.hpp | 7 ++++++ include/boost/charconv/detail/dragonbox.hpp | 24 ++++++++++--------- .../boost/charconv/detail/dragonbox_cache.hpp | 12 ++++++++++ include/boost/charconv/detail/policies.hpp | 4 ++-- 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/include/boost/charconv/detail/bit_layouts.hpp b/include/boost/charconv/detail/bit_layouts.hpp index 9cfb49b..ea20e08 100644 --- a/include/boost/charconv/detail/bit_layouts.hpp +++ b/include/boost/charconv/detail/bit_layouts.hpp @@ -36,16 +36,6 @@ struct ieee754_binary32 static constexpr int decimal_digits = 9; }; -#ifdef BOOST_NO_CXX17_INLINE_VARIABLES -// Definitions of in-class constexpr members are allowed but deprecated in C++17 -constexpr int ieee754_binary32::significand_bits; -constexpr int ieee754_binary32::exponent_bits; -constexpr int ieee754_binary32::min_exponent; -constexpr int ieee754_binary32::max_exponent; -constexpr int ieee754_binary32::exponent_bias; -constexpr int ieee754_binary32::decimal_digits; -#endif - struct IEEEd2bits { #if BOOST_CHARCONV_ENDIAN_LITTLE_BYTE @@ -71,16 +61,6 @@ struct ieee754_binary64 static constexpr int decimal_digits = 17; }; -#ifdef BOOST_NO_CXX17_INLINE_VARIABLES -// Definitions of in-class constexpr members are allowed but deprecated in C++17 -constexpr int ieee754_binary64::significand_bits; -constexpr int ieee754_binary64::exponent_bits; -constexpr int ieee754_binary64::min_exponent; -constexpr int ieee754_binary64::max_exponent; -constexpr int ieee754_binary64::exponent_bias; -constexpr int ieee754_binary64::decimal_digits; -#endif - // 80 bit long double (e.g. x86-64) #if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 diff --git a/include/boost/charconv/detail/config.hpp b/include/boost/charconv/detail/config.hpp index 8758e08..b2688d8 100644 --- a/include/boost/charconv/detail/config.hpp +++ b/include/boost/charconv/detail/config.hpp @@ -39,6 +39,13 @@ # define BOOST_CHARCONV_GCC5_CONSTEXPR BOOST_CHARCONV_CXX14_CONSTEXPR #endif +// C++17 allowed for constexpr lambdas +#if defined(__cpp_constexpr) && __cpp_constexpr >= 201603L +# define BOOST_CHARCONV_CXX17_CONSTEXPR constexpr +#else +# define BOOST_CHARCONV_CXX17_CONSTEXPR inline +#endif + // Determine endianness #if defined(_WIN32) diff --git a/include/boost/charconv/detail/dragonbox.hpp b/include/boost/charconv/detail/dragonbox.hpp index 0f512de..e2458df 100644 --- a/include/boost/charconv/detail/dragonbox.hpp +++ b/include/boost/charconv/detail/dragonbox.hpp @@ -339,7 +339,9 @@ struct impl : private FloatTraits, private FloatTraits::format // Compute xi and deltai. // 10^kappa <= deltai < 10^(kappa + 1) const auto deltai = compute_delta(cache, beta); - auto [xi, is_x_integer] = compute_mul(two_fc << beta, cache); + const auto x_result = compute_mul(two_fc << beta, cache); + auto xi = x_result.result; + auto is_x_integer = x_result.is_integer; // Deal with the unique exceptional cases // 29711844 * 2^-82 @@ -489,7 +491,7 @@ struct impl : private FloatTraits, private FloatTraits::format { BOOST_CHARCONV_ASSERT(n != 0); - BOOST_IF_CONSTEXPR (std::is_same_v) + BOOST_IF_CONSTEXPR (std::is_same::value) { constexpr auto mod_inv_5 = UINT32_C(0xcccccccd); constexpr auto mod_inv_25 = mod_inv_5 * mod_inv_5; @@ -519,7 +521,7 @@ struct impl : private FloatTraits, private FloatTraits::format } else { - static_assert(std::is_same::value); + static_assert(std::is_same::value, "Type must be binary64"); // Divide by 10^8 and reduce to 32-bits if divisible. // Since ret_value.significand <= (2^53 * 1000 - 1) / 1000 < 10^16, @@ -602,7 +604,7 @@ struct impl : private FloatTraits, private FloatTraits::format } else { - static_assert(std::is_same::value); + static_assert(std::is_same::value, "Type must be binary64"); auto r = umul192_upper128(u, cache); return {r.high, r.low == 0}; } @@ -616,7 +618,7 @@ struct impl : private FloatTraits, private FloatTraits::format } else { - static_assert(std::is_same::value); + static_assert(std::is_same::value, "Type must be binary64"); return static_cast(cache.high >> (carrier_bits - 1 - beta)); } } @@ -632,7 +634,7 @@ struct impl : private FloatTraits, private FloatTraits::format } else { - static_assert(std::is_same::value); + static_assert(std::is_same::value, "Type must be binary64"); auto r = umul192_lower128(two_f, cache); return {((r.high >> (64 - beta)) & 1) != 0, ((r.high << beta) | (r.low >> (64 - beta))) == 0}; } @@ -647,7 +649,7 @@ struct impl : private FloatTraits, private FloatTraits::format } else { - static_assert(std::is_same::value); + static_assert(std::is_same::value, "Type must be binary64"); return (cache.high - (cache.high >> (significand_bits + 2))) >> (carrier_bits - significand_bits - 1 - beta); } } @@ -661,7 +663,7 @@ struct impl : private FloatTraits, private FloatTraits::format } else { - static_assert(std::is_same::value); + static_assert(std::is_same::value, "Type must be binary64"); return (cache.high + (cache.high >> (significand_bits + 1))) >> (carrier_bits - significand_bits - 1 - beta); } } @@ -674,7 +676,7 @@ struct impl : private FloatTraits, private FloatTraits::format } else { - static_assert(std::is_same::value); + static_assert(std::is_same::value, "Type must be binary64"); return ((cache.high >> (carrier_bits - significand_bits - 2 - beta)) + 1) / 2; } } @@ -757,7 +759,7 @@ BOOST_FORCEINLINE BOOST_CHARCONV_SAFEBUFFERS auto to_decimal(signed_significand_ // 10^-308. This is indeed of the shortest length, and it is the unique one // closest to the true value among valid representations of the same length. static_assert(std::is_same::value || - std::is_same::value); + std::is_same::value, "Type must be either binary 32 or 64"); if (two_fc == 0) { @@ -816,7 +818,7 @@ BOOST_FORCEINLINE BOOST_CHARCONV_SAFEBUFFERS auto to_decimal(signed_significand_ } else { - static_assert(tag == decimal_to_binary_rounding::tag_t::right_closed_directed); + static_assert(tag == decimal_to_binary_rounding::tag_t::right_closed_directed, "Tag must be right_closed_direction"); bool shorter_interval {}; diff --git a/include/boost/charconv/detail/dragonbox_cache.hpp b/include/boost/charconv/detail/dragonbox_cache.hpp index e43f810..9310960 100644 --- a/include/boost/charconv/detail/dragonbox_cache.hpp +++ b/include/boost/charconv/detail/dragonbox_cache.hpp @@ -389,6 +389,7 @@ struct compressed_cache_detail (cache_holder::max_k - cache_holder::min_k + compression_ratio) / compression_ratio; +/* struct cache_holder_t { value128 table[compressed_table_size]; @@ -418,6 +419,17 @@ struct compressed_cache_detail } return res; }(); +*/ + // TODO: Pre-calculate the tables from above to use with C++14 and below + struct cache_holder_t + { + static value128 table[compressed_table_size]; + }; + + struct pow5_holder_t + { + static std::uint64_t table[compression_ratio]; + }; }; #ifdef BOOST_NO_CXX17_INLINE_VARIABLES diff --git a/include/boost/charconv/detail/policies.hpp b/include/boost/charconv/detail/policies.hpp index f274217..b9d1737 100644 --- a/include/boost/charconv/detail/policies.hpp +++ b/include/boost/charconv/detail/policies.hpp @@ -632,7 +632,7 @@ namespace policy_impl { const auto offset = k - kb; // Get the base cache. - const value128 base_cache = compressed_cache_detail::cache.table[cache_index]; + const value128 base_cache = compressed_cache_detail::cache_holder_t::table[cache_index]; if (offset == 0) { @@ -645,7 +645,7 @@ namespace policy_impl { BOOST_CHARCONV_ASSERT(alpha > 0 && alpha < 64); // Try to recover the real cache. - const auto pow5 = compressed_cache_detail::pow5.table[offset]; + const auto pow5 = compressed_cache_detail::pow5_holder_t::table[offset]; auto recovered_cache = full_multiplication(base_cache.high, pow5); const auto middle_low = full_multiplication(base_cache.low, pow5);