Unbloat chrono

This commit is contained in:
Victor Zverovich 2024-07-22 14:37:02 -07:00
parent 42d3d703b5
commit f6b4a23b83
4 changed files with 10 additions and 10 deletions

View File

@ -2279,7 +2279,7 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
// As a possible future optimization, we could avoid extra copying if width
// is not specified.
auto buf = basic_memory_buffer<Char>();
auto out = std::back_inserter(buf);
auto out = basic_appender<Char>(buf);
detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_,
ctx);
detail::handle_dynamic_spec<detail::precision_checker>(precision,
@ -2388,7 +2388,7 @@ template <typename Char> struct formatter<std::tm, Char> {
const Duration* subsecs) const -> decltype(ctx.out()) {
auto specs = specs_;
auto buf = basic_memory_buffer<Char>();
auto out = std::back_inserter(buf);
auto out = basic_appender<Char>(buf);
detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_,
ctx);

View File

@ -494,9 +494,9 @@ auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args)
template <typename S, typename... Args,
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args)
-> size_t {
return fmt::format_to(detail::counting_iterator(), fmt, args...).count();
auto formatted_size(const S& fmt, const Args&... args) -> size_t {
auto buf = detail::counting_buffer<>();
return fmt::format_to(fmt::appender(buf), fmt, args...).count();
}
template <typename S, typename... Args,

View File

@ -1314,10 +1314,10 @@ FMT_CONSTEXPR20 auto format_decimal(Char* out, UInt value, int size)
return {begin + n, end};
}
template <typename Char, typename UInt, typename Iterator,
FMT_ENABLE_IF(!std::is_pointer<remove_cvref_t<Iterator>>::value)>
FMT_CONSTEXPR inline auto format_decimal(Iterator out, UInt value, int size)
-> format_decimal_result<Iterator> {
template <typename Char, typename UInt, typename OutputIt,
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value)>
FMT_CONSTEXPR inline auto format_decimal(OutputIt out, UInt value, int size)
-> format_decimal_result<OutputIt> {
// Buffer is large enough to hold all digits (digits10 + 1).
Char buffer[digits10<UInt>() + 1] = {};
auto end = format_decimal(buffer, value, size).end;

View File

@ -206,7 +206,7 @@ TEST(compile_test, format_to_n) {
EXPECT_STREQ("2a", buffer);
}
# ifdef __cpp_lib_bit_cast
# if 0
TEST(compile_test, constexpr_formatted_size) {
FMT_CONSTEXPR20 size_t size = fmt::formatted_size(FMT_COMPILE("{}"), 42);
EXPECT_EQ(size, 2);