diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 35fe63f8..0235cbc1 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -164,8 +164,10 @@ template void format_arg( basic_format_parse_context& parse_ctx, Context& ctx, Id arg_id) { - ctx.advance_to( - visit_format_arg(arg_formatter(ctx, &parse_ctx), ctx.arg(arg_id))); + ctx.advance_to(visit_format_arg( + arg_formatter( + ctx, &parse_ctx), + ctx.arg(arg_id))); } // vformat_to is defined in a subnamespace to prevent ADL. @@ -225,8 +227,10 @@ auto vformat_to(Range out, CompiledFormat& cf, basic_format_args args) if (specs.precision >= 0) checker.check_precision(); advance_to(parse_ctx, part.arg_id_end); - ctx.advance_to( - visit_format_arg(arg_formatter(ctx, nullptr, &specs), arg)); + ctx.advance_to(visit_format_arg( + arg_formatter( + ctx, nullptr, &specs), + arg)); break; } } diff --git a/include/fmt/format.h b/include/fmt/format.h index f5829a6d..7b73f8af 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2723,21 +2723,17 @@ FMT_API void report_error(format_func func, int error_code, } // namespace detail /** The default argument formatter. */ -template -class arg_formatter - : public detail::arg_formatter_base { +template +class arg_formatter : public detail::arg_formatter_base { private: - using char_type = typename Range::value_type; - using base = detail::arg_formatter_base; - using context_type = basic_format_context; + using char_type = Char; + using base = detail::arg_formatter_base; + using context_type = basic_format_context; context_type& ctx_; basic_format_parse_context* parse_ctx_; public: - using range = Range; using iterator = typename base::iterator; using format_specs = typename base::format_specs; @@ -2990,9 +2986,9 @@ struct formatter( specs_.precision, specs_.precision_ref, ctx); - using range_type = detail::output_range; - return visit_format_arg(arg_formatter(ctx, nullptr, &specs_), + using af = arg_formatter; + return visit_format_arg(af(ctx, nullptr, &specs_), detail::make_arg(val)); } @@ -3086,9 +3082,9 @@ template class dynamic_formatter { } if (specs_.alt) checker.on_hash(); if (specs_.precision >= 0) checker.end_precision(); - using range = detail::output_range; - visit_format_arg(arg_formatter(ctx, nullptr, &specs_), + using af = arg_formatter; + visit_format_arg(af(ctx, nullptr, &specs_), detail::make_arg(val)); return ctx.out(); } @@ -3113,11 +3109,11 @@ FMT_CONSTEXPR void advance_to( template struct format_handler : detail::error_handler { - using range = typename ArgFormatter::range; + using iterator = typename ArgFormatter::iterator; - format_handler(range r, basic_string_view str, + format_handler(iterator out, basic_string_view str, basic_format_args format_args, detail::locale_ref loc) - : parse_context(str), context(r.begin(), format_args, loc) {} + : parse_context(str), context(out, format_args, loc) {} void on_text(const Char* begin, const Char* end) { auto size = detail::to_unsigned(end - begin); @@ -3170,7 +3166,7 @@ struct format_handler : detail::error_handler { /** Formats arguments and writes the output to the range. */ template typename Context::iterator vformat_to( - typename ArgFormatter::range out, basic_string_view format_str, + typename ArgFormatter::iterator out, basic_string_view format_str, basic_format_args args, detail::locale_ref loc = detail::locale_ref()) { format_handler h(out, format_str, args, loc); @@ -3334,9 +3330,9 @@ template typename buffer_context::iterator detail::vformat_to( detail::buffer& buf, basic_string_view format_str, basic_format_args>> args) { - using range = buffer_range; - return vformat_to>(buf, to_string_view(format_str), - args); + using af = arg_formatter::iterator, Char>; + return vformat_to(std::back_inserter(buf), to_string_view(format_str), + args); } #ifndef FMT_HEADER_ONLY @@ -3397,9 +3393,8 @@ template < inline OutputIt vformat_to( OutputIt out, const S& format_str, format_args_t, char_t> args) { - using range = detail::output_range>; - return vformat_to>(range(out), - to_string_view(format_str), args); + using af = arg_formatter>; + return vformat_to(out, to_string_view(format_str), args); } /** diff --git a/include/fmt/locale.h b/include/fmt/locale.h index 34b5c890..dd75b45f 100644 --- a/include/fmt/locale.h +++ b/include/fmt/locale.h @@ -20,9 +20,9 @@ typename buffer_context::iterator vformat_to( const std::locale& loc, buffer& buf, basic_string_view format_str, basic_format_args>> args) { - using range = buffer_range; - return vformat_to>(buf, to_string_view(format_str), args, - detail::locale_ref(loc)); + using af = arg_formatter::iterator, Char>; + return vformat_to(std::back_inserter(buf), to_string_view(format_str), + args, detail::locale_ref(loc)); } template @@ -56,9 +56,9 @@ template , Char> args) { - using range = detail::output_range; - return vformat_to>( - range(out), to_string_view(format_str), args, detail::locale_ref(loc)); + using af = arg_formatter; + return vformat_to(out, to_string_view(format_str), args, + detail::locale_ref(loc)); } template > { + : public fmt::arg_formatter { public: - using range = fmt::buffer_range; - typedef fmt::arg_formatter base; + using base = fmt::arg_formatter; custom_arg_formatter(fmt::format_context& ctx, fmt::format_parse_context* parse_ctx, @@ -39,8 +38,10 @@ class custom_arg_formatter std::string custom_vformat(fmt::string_view format_str, fmt::format_args args) { fmt::memory_buffer buffer; + fmt::internal::buffer& base = buffer; // Pass custom argument formatter as a template arg to vwrite. - fmt::vformat_to(buffer, format_str, args); + fmt::vformat_to(std::back_inserter(base), format_str, + args); return std::string(buffer.data(), buffer.size()); } diff --git a/test/format-test.cc b/test/format-test.cc index 19d16e2f..b8e56ee2 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1847,7 +1847,9 @@ class mock_arg_formatter static void custom_vformat(fmt::string_view format_str, fmt::format_args args) { fmt::memory_buffer buffer; - fmt::vformat_to(buffer, format_str, args); + fmt::internal::buffer& base = buffer; + fmt::vformat_to(std::back_inserter(base), format_str, + args); } template diff --git a/test/ostream-test.cc b/test/ostream-test.cc index b7be4796..d9dfb6c6 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -64,12 +64,13 @@ TEST(OStreamTest, Enum) { EXPECT_EQ(L"0", fmt::format(L"{}", unstreamable_enum())); } -using range = fmt::buffer_range; - -struct test_arg_formatter : fmt::arg_formatter { +struct test_arg_formatter + : fmt::arg_formatter::iterator, char> { fmt::format_parse_context parse_ctx; test_arg_formatter(fmt::format_context& ctx, fmt::format_specs& s) - : fmt::arg_formatter(ctx, &parse_ctx, &s), parse_ctx("") {} + : fmt::arg_formatter::iterator, char>( + ctx, &parse_ctx, &s), + parse_ctx("") {} }; TEST(OStreamTest, CustomArg) {