Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions doc/decimal/cstdio.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ namespace decimal {
template <typename... Dec>
int snprintf(char* buffer, std::size_t buf_size, const char* format, Dec... value) noexcept;

template <typename... Dec>
int sprintf(char* buffer, const char* format, Dec... value) noexcept;

template <typename... Dec>
int fprintf(std::FILE* buffer, const char* format, Dec... values) noexcept;

Expand All @@ -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:
Expand Down
29 changes: 9 additions & 20 deletions include/boost/decimal/cstdio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ inline void make_uppercase(char* first, const char* last) noexcept
template <typename... T>
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<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
-> std::enable_if_t<detail::conjunction_v<detail::is_decimal_floating_point<T>...>, int>
#else
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
-> int requires detail::conjunction_v<detail::is_decimal_floating_point<T>...>
#endif
{
if (buffer == nullptr || format == nullptr)
Expand Down Expand Up @@ -246,31 +246,20 @@ inline auto snprintf_impl(char* buffer, std::size_t buf_size, const char* format
template <typename... T>
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<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
-> std::enable_if_t<detail::conjunction_v<detail::is_decimal_floating_point<T>...>, int>
#else
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
-> int requires detail::conjunction_v<detail::is_decimal_floating_point<T>...>
#endif
{
return detail::snprintf_impl(buffer, buf_size, format, values...);
}

template <typename... T>
inline auto sprintf(char* buffer, const char* format, T... values) noexcept
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
-> std::enable_if_t<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
#else
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
#endif
{
return detail::snprintf_impl(buffer, sizeof(buffer), format, values...);
}

template <typename... T>
inline auto fprintf(std::FILE* buffer, const char* format, T... values) noexcept
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
-> std::enable_if_t<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
-> std::enable_if_t<detail::conjunction_v<detail::is_decimal_floating_point<T>...>, int>
#else
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
-> int requires detail::conjunction_v<detail::is_decimal_floating_point<T>...>
#endif
{
if (format == nullptr)
Expand Down Expand Up @@ -319,9 +308,9 @@ inline auto fprintf(std::FILE* buffer, const char* format, T... values) noexcept
template <typename... T>
inline auto printf(const char* format, T... values) noexcept
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
-> std::enable_if_t<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
-> std::enable_if_t<detail::conjunction_v<detail::is_decimal_floating_point<T>...>, int>
#else
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
-> int requires detail::conjunction_v<detail::is_decimal_floating_point<T>...>
#endif
{
return fprintf(stdout, format, values...);
Expand Down
13 changes: 13 additions & 0 deletions include/boost/decimal/detail/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ constexpr bool is_decimal_floating_point<T>::value;
template <typename T>
constexpr bool is_decimal_floating_point_v = is_decimal_floating_point<T>::value;

template <typename...>
struct conjunction : std::true_type {};

template <typename B1>
struct conjunction<B1> : B1 {};

template <typename B1, typename... Bn>
struct conjunction<B1, Bn...>
: std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};

template <typename... B>
BOOST_DECIMAL_CONSTEXPR_VARIABLE bool conjunction_v = conjunction<B...>::value;

} // namespace detail
} // namespace decimal
} // namespace boost
Expand Down
Loading