Skip to content

Commit 3d16a3f

Browse files
committed
Add limits struct like boost charconv
1 parent 3ebfb24 commit 3d16a3f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/boost/decimal/charconv.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,18 @@ BOOST_DECIMAL_EXPORT BOOST_DECIMAL_CONSTEXPR auto to_chars(char* first, char* la
812812
return detail::to_chars_impl(first, last, value, fmt, precision);
813813
}
814814

815+
template <typename T>
816+
struct limits
817+
{
818+
BOOST_DECIMAL_ATTRIBUTE_UNUSED static constexpr int max_chars = boost::decimal::detail::max_string_length_v<T>;
819+
};
820+
821+
#if !(defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L) && (!defined(_MSC_VER) || _MSC_VER != 1900)
822+
823+
template <typename T> BOOST_DECIMAL_ATTRIBUTE_UNUSED constexpr int limits<T>::max_chars;
824+
825+
#endif
826+
815827
} //namespace decimal
816828
} //namespace boost
817829

include/boost/decimal/detail/attributes.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ template <>
7878
BOOST_DECIMAL_CONSTEXPR_VARIABLE_SPECIALIZATION auto max_significand_v<decimal128> =
7979
uint128{UINT64_C(0b1111111111'1111111111'1111111111'1111111111'111111), UINT64_MAX};
8080

81+
// sign + decimal digits + '.' + 'e' + '+/-' + max digits of exponent + null term
8182
template <typename Dec, std::enable_if_t<detail::is_decimal_floating_point_v<Dec>, bool> = true>
8283
BOOST_DECIMAL_ATTRIBUTE_UNUSED BOOST_DECIMAL_CONSTEXPR_VARIABLE auto max_string_length_v = std::is_same<Dec, decimal32>::value ? 15 : 25;
8384

0 commit comments

Comments
 (0)