Skip to content

Commit 6aa62b9

Browse files
authored
Merge pull request #813 from cppalliance/803
Remove `sprintf` and fix conceptual requirements for <cstdio>
2 parents 9bcc0d2 + ad00b1e commit 6aa62b9

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

doc/decimal/cstdio.adoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ namespace decimal {
2020
template <typename... Dec>
2121
int snprintf(char* buffer, std::size_t buf_size, const char* format, Dec... value) noexcept;
2222
23-
template <typename... Dec>
24-
int sprintf(char* buffer, const char* format, Dec... value) noexcept;
25-
2623
template <typename... Dec>
2724
int fprintf(std::FILE* buffer, const char* format, Dec... values) noexcept;
2825
@@ -33,8 +30,6 @@ int printf(const char* format, Dec... values) noexcept;
3330
} //namespace boost
3431
----
3532

36-
WARNING: In the interest of safety `sprintf` simply calls `snprintf` with buf_size equal to sizeof(buffer).
37-
3833
=== Type Modifiers
3934

4035
The type modifiers to be used are:

include/boost/decimal/cstdio.hpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ inline void make_uppercase(char* first, const char* last) noexcept
157157
template <typename... T>
158158
inline auto snprintf_impl(char* buffer, std::size_t buf_size, const char* format, T... values) noexcept
159159
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
160-
-> std::enable_if_t<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
160+
-> std::enable_if_t<detail::conjunction_v<detail::is_decimal_floating_point<T>...>, int>
161161
#else
162-
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
162+
-> int requires detail::conjunction_v<detail::is_decimal_floating_point<T>...>
163163
#endif
164164
{
165165
if (buffer == nullptr || format == nullptr)
@@ -246,31 +246,20 @@ inline auto snprintf_impl(char* buffer, std::size_t buf_size, const char* format
246246
template <typename... T>
247247
inline auto snprintf(char* buffer, std::size_t buf_size, const char* format, T... values) noexcept
248248
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
249-
-> std::enable_if_t<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
249+
-> std::enable_if_t<detail::conjunction_v<detail::is_decimal_floating_point<T>...>, int>
250250
#else
251-
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
251+
-> int requires detail::conjunction_v<detail::is_decimal_floating_point<T>...>
252252
#endif
253253
{
254254
return detail::snprintf_impl(buffer, buf_size, format, values...);
255255
}
256256

257-
template <typename... T>
258-
inline auto sprintf(char* buffer, const char* format, T... values) noexcept
259-
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
260-
-> std::enable_if_t<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
261-
#else
262-
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
263-
#endif
264-
{
265-
return detail::snprintf_impl(buffer, sizeof(buffer), format, values...);
266-
}
267-
268257
template <typename... T>
269258
inline auto fprintf(std::FILE* buffer, const char* format, T... values) noexcept
270-
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
271-
-> std::enable_if_t<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
259+
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
260+
-> std::enable_if_t<detail::conjunction_v<detail::is_decimal_floating_point<T>...>, int>
272261
#else
273-
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
262+
-> int requires detail::conjunction_v<detail::is_decimal_floating_point<T>...>
274263
#endif
275264
{
276265
if (format == nullptr)
@@ -319,9 +308,9 @@ inline auto fprintf(std::FILE* buffer, const char* format, T... values) noexcept
319308
template <typename... T>
320309
inline auto printf(const char* format, T... values) noexcept
321310
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
322-
-> std::enable_if_t<detail::is_decimal_floating_point_v<std::common_type_t<T...>>, int>
311+
-> std::enable_if_t<detail::conjunction_v<detail::is_decimal_floating_point<T>...>, int>
323312
#else
324-
-> int requires detail::is_decimal_floating_point_v<std::common_type_t<T...>>
313+
-> int requires detail::conjunction_v<detail::is_decimal_floating_point<T>...>
325314
#endif
326315
{
327316
return fprintf(stdout, format, values...);

include/boost/decimal/detail/type_traits.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ constexpr bool is_decimal_floating_point<T>::value;
156156
template <typename T>
157157
constexpr bool is_decimal_floating_point_v = is_decimal_floating_point<T>::value;
158158

159+
template <typename...>
160+
struct conjunction : std::true_type {};
161+
162+
template <typename B1>
163+
struct conjunction<B1> : B1 {};
164+
165+
template <typename B1, typename... Bn>
166+
struct conjunction<B1, Bn...>
167+
: std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
168+
169+
template <typename... B>
170+
BOOST_DECIMAL_CONSTEXPR_VARIABLE bool conjunction_v = conjunction<B...>::value;
171+
159172
} // namespace detail
160173
} // namespace decimal
161174
} // namespace boost

0 commit comments

Comments
 (0)