2626#include < boost/decimal/detail/countl.hpp>
2727#include < boost/decimal/detail/remove_trailing_zeros.hpp>
2828#include < boost/decimal/detail/promotion.hpp>
29- #include < boost/decimal/detail/quantum_preservation_format.hpp>
3029
3130#ifndef BOOST_DECIMAL_BUILD_MODULE
3231#include < cstdint>
@@ -1212,6 +1211,20 @@ constexpr auto to_chars_impl(char* first, char* last, const TargetDecimalType& v
12121211 return to_chars_scientific_impl (first, last, value, fmt);
12131212 case chars_format::hex:
12141213 return to_chars_hex_impl (first, last, value);
1214+ case chars_format::cohort_preserving_scientific:
1215+ BOOST_DECIMAL_IF_CONSTEXPR (detail::is_fast_type_v<TargetDecimalType>)
1216+ {
1217+ // Fast types have no concept of cohorts
1218+ return {last, std::errc::invalid_argument};
1219+ }
1220+
1221+ if (local_precision != -1 )
1222+ {
1223+ // Precision and cohort preservation are mutually exclusive options
1224+ return {last, std::errc::invalid_argument};
1225+ }
1226+
1227+ return to_chars_cohort_preserving_scientific (first, last, value);
12151228 // LCOV_EXCL_START
12161229 default :
12171230 BOOST_DECIMAL_UNREACHABLE;
@@ -1243,38 +1256,6 @@ constexpr auto to_chars_impl(char* first, char* last, const TargetDecimalType& v
12431256 return to_chars_scientific_impl (first, last, value, fmt, local_precision); // LCOV_EXCL_LINE
12441257}
12451258
1246- // TODO(mborland): Remove once other modes are inplace
1247- #ifdef _MSC_VER
1248- # pragma warning(push)
1249- # pragma warning(disable: 4065)
1250- #endif
1251-
1252- template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetDecimalType>
1253- constexpr auto to_chars_impl (char * first, char * last, const TargetDecimalType& value, const chars_format fmt, const quantum_preservation method) noexcept -> to_chars_result
1254- {
1255- // No quantum preservation is the same thing as regular to_chars
1256- if (method == quantum_preservation::off)
1257- {
1258- return to_chars_impl (first, last, value, fmt);
1259- }
1260-
1261- // Sanity check our bounds
1262- if (BOOST_DECIMAL_UNLIKELY (first >= last))
1263- {
1264- return {last, std::errc::invalid_argument};
1265- }
1266-
1267- switch (fmt)
1268- {
1269- default :
1270- return to_chars_cohort_preserving_scientific (first, last, value);
1271- }
1272- }
1273-
1274- #ifdef _MSC_VER
1275- # pragma warning(pop)
1276- #endif
1277-
12781259} // namespace detail
12791260
12801261BOOST_DECIMAL_EXPORT template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetDecimalType>
@@ -1300,13 +1281,6 @@ constexpr auto to_chars(char* first, char* last, const TargetDecimalType& value,
13001281 return detail::to_chars_impl (first, last, value, fmt, precision);
13011282}
13021283
1303- BOOST_DECIMAL_EXPORT template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetDecimalType>
1304- constexpr auto to_chars (char * first, char * last, const TargetDecimalType& value, const chars_format fmt, const quantum_preservation method) noexcept -> to_chars_result
1305- {
1306- static_assert (detail::is_ieee_type_v<TargetDecimalType>, " Fast types are automatically normalized, so they have no concept of quantum preservation" );
1307- return detail::to_chars_impl (first, last, value, fmt, method);
1308- }
1309-
13101284#ifdef BOOST_DECIMAL_HAS_STD_CHARCONV
13111285
13121286BOOST_DECIMAL_EXPORT template <typename DecimalType>
0 commit comments