From cec750702bb2fb0283ca59e372e7fb9ea5204867 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 19 Apr 2023 16:12:44 +0200 Subject: [PATCH] Define two cache holders rather than specialize a template struct --- include/boost/charconv/detail/dragonbox.hpp | 41 ++++++++++----------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/include/boost/charconv/detail/dragonbox.hpp b/include/boost/charconv/detail/dragonbox.hpp index e20e86f..fb63117 100644 --- a/include/boost/charconv/detail/dragonbox.hpp +++ b/include/boost/charconv/detail/dragonbox.hpp @@ -475,11 +475,7 @@ using signed_decimal_fp = decimal_fp; // Computed cache entries. //////////////////////////////////////////////////////////////////////////////////////// -template -struct cache_holder; - -template <> -struct cache_holder +struct cache_holder_ieee754_binary32 { using cache_entry_type = std::uint64_t; static constexpr int cache_bits = 64; @@ -510,15 +506,14 @@ struct cache_holder #if defined(BOOST_NO_CXX17_INLINE_VARIABLES) -constexpr int cache_holder::cache_bits; -constexpr int cache_holder::min_k; -constexpr int cache_holder::max_k; -constexpr typename cache_holder::cache_entry_type cache_holder::cache[]; +constexpr int cache_holder_ieee754_binary32::cache_bits; +constexpr int cache_holder_ieee754_binary32::min_k; +constexpr int cache_holder_ieee754_binary32::max_k; +constexpr typename cache_holder_ieee754_binary32::cache_entry_type cache_holder_ieee754_binary32::cache[]; #endif -template <> -struct cache_holder +struct cache_holder_ieee754_binary64 { using cache_entry_type = uint128; static constexpr int cache_bits = 128; @@ -839,10 +834,10 @@ struct cache_holder #if defined(BOOST_NO_CXX17_INLINE_VARIABLES) -constexpr int cache_holder::cache_bits; -constexpr int cache_holder::min_k; -constexpr int cache_holder::max_k; -constexpr typename cache_holder::cache_entry_type cache_holder::cache[]; +constexpr int cache_holder_ieee754_binary64::cache_bits; +constexpr int cache_holder_ieee754_binary64::min_k; +constexpr int cache_holder_ieee754_binary64::max_k; +constexpr typename cache_holder_ieee754_binary64::cache_entry_type cache_holder_ieee754_binary64::cache[]; #endif @@ -1425,11 +1420,12 @@ namespace cache { { using cache_policy = full; - template - static constexpr typename cache_holder::cache_entry_type get_cache(int k) noexcept + template ::value, + cache_holder_ieee754_binary32, + cache_holder_ieee754_binary64>::type> + static constexpr typename cache_format::cache_entry_type get_cache(int k) noexcept { - // assert(k >= cache_holder::min_k && k <= cache_holder::max_k); - return cache_holder::cache[std::size_t(k - cache_holder::min_k)]; + return cache_format::cache[std::size_t(k - cache_format::min_k)]; } }; } @@ -1530,8 +1526,11 @@ struct impl : private FloatTraits, private FloatTraits::format static constexpr int max_k_b = -log::floor_log10_pow2(int(min_exponent - significand_bits)) + kappa; static constexpr int max_k = max_k_a > max_k_b ? max_k_a : max_k_b; - using cache_entry_type = typename cache_holder::cache_entry_type; - static constexpr auto cache_bits = cache_holder::cache_bits; + using cache_format = typename std::conditional::value, + cache_holder_ieee754_binary32, + cache_holder_ieee754_binary64>::type; + using cache_entry_type = typename cache_format::cache_entry_type; + static constexpr auto cache_bits = cache_format::cache_bits; static constexpr int case_shorter_interval_left_endpoint_lower_threshold = 2; static BOOST_CXX14_CONSTEXPR const int case_shorter_interval_left_endpoint_upper_threshold = 3;