
On Thursday, January 16th, 2025 at 11:45 AM, Peter Dimov via Boost <boost@lists.boost.org> wrote:
Ruben Perez wrote:
4. From sprintf's documentation: "In the interest of safety sprintf simply calls snprintf with buf_size equal to sizeof(buffer). ". This doesn't look right. This is what the implementation looks like:
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
...
It would be better to make the constraint say what we actually mean, namely, "each type in T... should be integral, floating point, or decimal floating point".
Using something entirely different just because we think it's equivalent to the above isn't superior in any way to just saying what we actually mean, even if it were actually equivalent. (It isn't because common_type can be specialized by the user.)
I guess I don't know a "superior" way to write all types in T should be decimal floating point types. I thought that was pretty succinct and communicated requirements fine.
(Providing sprintf in 2025 is a bit debatable, std::format is the way to go here.)
I found that to get <format> to actually work correctly you need GCC >= 13, Clang >= 18, and MSVC >= 1940 which is a relatively high bar. Matt