Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:57

0001 // Copyright 2023 Matt Borland
0002 // Distributed under the Boost Software License, Version 1.0.
0003 // https://www.boost.org/LICENSE_1_0.txt
0004 
0005 #ifndef BOOST_JSON_DETAIL_CHARCONV_LIMITS_HPP
0006 #define BOOST_JSON_DETAIL_CHARCONV_LIMITS_HPP
0007 
0008 #include <boost/config.hpp>
0009 #include <limits>
0010 #include <type_traits>
0011 
0012 namespace boost { namespace json { namespace detail { namespace charconv {
0013 
0014 // limits<T>::max_chars10: the minimum size of the buffer that needs to be
0015 //   passed to to_chars to guarantee successful conversion for all values of
0016 //   type T, when either no base is passed, or base 10 is passed
0017 //
0018 // limits<T>::max_chars: the minimum size of the buffer that needs to be
0019 //   passed to to_chars to guarantee successful conversion for all values of
0020 //   type T, for any value of base
0021 
0022 namespace detail
0023 {
0024 
0025 constexpr int exp_digits( int exp )
0026 {
0027     return exp < 100? 2: exp < 1000? 3: exp < 10000? 4: 5;
0028 }
0029 
0030 #if defined(BOOST_HAS_INT128)
0031 
0032 template<class T> struct is_int128: std::is_same<T, boost::int128_type> {};
0033 template<class T> struct is_uint128: std::is_same<T, boost::int128_type> {};
0034 
0035 #else
0036 
0037 template<class T> struct is_int128: std::false_type {};
0038 template<class T> struct is_uint128: std::false_type {};
0039 
0040 #endif
0041 
0042 } // namespace detail
0043 
0044 template<typename T> struct limits
0045 {
0046     static constexpr int max_chars10 =
0047 
0048         // int128_t
0049         detail::is_int128<T>::value? 38+2: // digits10 + 1 + sign
0050 
0051         // uint128_t
0052         detail::is_uint128<T>::value? 38+1: // digits10 + 1
0053 
0054         // integral
0055         std::numeric_limits<T>::is_integer? std::numeric_limits<T>::digits10 + 1 + std::numeric_limits<T>::is_signed:
0056 
0057         // floating point
0058         std::numeric_limits<T>::max_digits10 + 3 + 2 + detail::exp_digits( std::numeric_limits<T>::max_exponent10 ); // -1.(max_digits10)e+(max_exp)
0059 
0060     static constexpr int max_chars =
0061 
0062         // int128_t
0063         detail::is_int128<T>::value? 127+2: // digits + 1 + sign
0064 
0065         // uint128_t
0066         detail::is_uint128<T>::value? 128+1: // digits + 1
0067 
0068         // integral
0069         std::numeric_limits<T>::is_integer? std::numeric_limits<T>::digits + 1 + std::numeric_limits<T>::is_signed:
0070 
0071         // floating point
0072         std::numeric_limits<T>::max_digits10 + 3 + 2 + detail::exp_digits( std::numeric_limits<T>::max_exponent10 ); // as above
0073 };
0074 
0075 #if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
0076 
0077 // Definitions of in-class constexpr members are allowed but deprecated in C++17
0078 
0079 template<typename T> constexpr int limits<T>::max_chars10;
0080 template<typename T> constexpr int limits<T>::max_chars;
0081 
0082 #endif // defined(BOOST_NO_CXX17_INLINE_VARIABLES)
0083 
0084 }}}} // namespace boost::charconv
0085 
0086 #endif // BOOST_JSON_DETAIL_CHARCONV_LIMITS_HPP