diff --git a/doc/decimal/cstdio.adoc b/doc/decimal/cstdio.adoc index 883ab6d11..2881b59a4 100644 --- a/doc/decimal/cstdio.adoc +++ b/doc/decimal/cstdio.adoc @@ -20,9 +20,6 @@ namespace decimal { template int snprintf(char* buffer, std::size_t buf_size, const char* format, Dec... value) noexcept; -template -int sprintf(char* buffer, const char* format, Dec... value) noexcept; - template int fprintf(std::FILE* buffer, const char* format, Dec... values) noexcept; @@ -33,8 +30,6 @@ int printf(const char* format, Dec... values) noexcept; } //namespace boost ---- -WARNING: In the interest of safety `sprintf` simply calls `snprintf` with buf_size equal to sizeof(buffer). - === Type Modifiers The type modifiers to be used are: diff --git a/include/boost/decimal/cstdio.hpp b/include/boost/decimal/cstdio.hpp index 1ab4388e5..edb18609d 100644 --- a/include/boost/decimal/cstdio.hpp +++ b/include/boost/decimal/cstdio.hpp @@ -157,9 +157,9 @@ inline void make_uppercase(char* first, const char* last) noexcept template inline auto snprintf_impl(char* buffer, std::size_t buf_size, const char* format, T... values) noexcept #ifndef BOOST_DECIMAL_HAS_CONCEPTS - -> std::enable_if_t>, int> + -> std::enable_if_t...>, int> #else - -> int requires detail::is_decimal_floating_point_v> + -> int requires detail::conjunction_v...> #endif { if (buffer == nullptr || format == nullptr) @@ -246,31 +246,20 @@ inline auto snprintf_impl(char* buffer, std::size_t buf_size, const char* format template inline auto snprintf(char* buffer, std::size_t buf_size, const char* format, T... values) noexcept #ifndef BOOST_DECIMAL_HAS_CONCEPTS - -> std::enable_if_t>, int> + -> std::enable_if_t...>, int> #else - -> int requires detail::is_decimal_floating_point_v> + -> int requires detail::conjunction_v...> #endif { return detail::snprintf_impl(buffer, buf_size, format, values...); } -template -inline auto sprintf(char* buffer, const char* format, T... values) noexcept - #ifndef BOOST_DECIMAL_HAS_CONCEPTS - -> std::enable_if_t>, int> - #else - -> int requires detail::is_decimal_floating_point_v> - #endif -{ - return detail::snprintf_impl(buffer, sizeof(buffer), format, values...); -} - template inline auto fprintf(std::FILE* buffer, const char* format, T... values) noexcept -#ifndef BOOST_DECIMAL_HAS_CONCEPTS - -> std::enable_if_t>, int> + #ifndef BOOST_DECIMAL_HAS_CONCEPTS + -> std::enable_if_t...>, int> #else - -> int requires detail::is_decimal_floating_point_v> + -> int requires detail::conjunction_v...> #endif { if (format == nullptr) @@ -319,9 +308,9 @@ inline auto fprintf(std::FILE* buffer, const char* format, T... values) noexcept template inline auto printf(const char* format, T... values) noexcept #ifndef BOOST_DECIMAL_HAS_CONCEPTS - -> std::enable_if_t>, int> + -> std::enable_if_t...>, int> #else - -> int requires detail::is_decimal_floating_point_v> + -> int requires detail::conjunction_v...> #endif { return fprintf(stdout, format, values...); diff --git a/include/boost/decimal/detail/type_traits.hpp b/include/boost/decimal/detail/type_traits.hpp index 5b7b841ec..0fd70f211 100644 --- a/include/boost/decimal/detail/type_traits.hpp +++ b/include/boost/decimal/detail/type_traits.hpp @@ -156,6 +156,19 @@ constexpr bool is_decimal_floating_point::value; template constexpr bool is_decimal_floating_point_v = is_decimal_floating_point::value; +template +struct conjunction : std::true_type {}; + +template +struct conjunction : B1 {}; + +template +struct conjunction + : std::conditional_t, B1> {}; + +template +BOOST_DECIMAL_CONSTEXPR_VARIABLE bool conjunction_v = conjunction::value; + } // namespace detail } // namespace decimal } // namespace boost