diff --git a/include/fmt/printf.h b/include/fmt/printf.h index b43f7e36..effb606c 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -222,7 +222,7 @@ auto make_arg_formatter(buffer_appender iter, format_specs& s) } // The ``printf`` argument formatter. -template +template class printf_arg_formatter : public arg_formatter { private: using base = arg_formatter; @@ -230,75 +230,77 @@ class printf_arg_formatter : public arg_formatter { context_type& context_; - auto write_null_pointer(bool is_string = false) -> OutputIt { + void write_null_pointer(bool is_string = false) { auto s = this->specs; s.type = presentation_type::none; - return write_bytes(this->out, is_string ? "(null)" : "(nil)", s); + write_bytes(this->out, is_string ? "(null)" : "(nil)", s); } public: - printf_arg_formatter(OutputIt iter, format_specs& s, context_type& ctx) + printf_arg_formatter(buffer_appender iter, format_specs& s, + context_type& ctx) : base(make_arg_formatter(iter, s)), context_(ctx) {} - auto operator()(monostate value) -> OutputIt { - return base::operator()(value); - } + void operator()(monostate value) { base::operator()(value); } template ::value)> - auto operator()(T value) -> OutputIt { + void operator()(T value) { // MSVC2013 fails to compile separate overloads for bool and Char so use // std::is_same instead. - if (std::is_same::value) { - format_specs fmt_specs = this->specs; - if (fmt_specs.type != presentation_type::none && - fmt_specs.type != presentation_type::chr) { - return (*this)(static_cast(value)); - } - fmt_specs.sign = sign::none; - fmt_specs.alt = false; - fmt_specs.fill[0] = ' '; // Ignore '0' flag for char types. - // align::numeric needs to be overwritten here since the '0' flag is - // ignored for non-numeric types - if (fmt_specs.align == align::none || fmt_specs.align == align::numeric) - fmt_specs.align = align::right; - return write(this->out, static_cast(value), fmt_specs); + if (!std::is_same::value) { + base::operator()(value); + return; } - return base::operator()(value); + format_specs fmt_specs = this->specs; + if (fmt_specs.type != presentation_type::none && + fmt_specs.type != presentation_type::chr) { + return (*this)(static_cast(value)); + } + fmt_specs.sign = sign::none; + fmt_specs.alt = false; + fmt_specs.fill[0] = ' '; // Ignore '0' flag for char types. + // align::numeric needs to be overwritten here since the '0' flag is + // ignored for non-numeric types + if (fmt_specs.align == align::none || fmt_specs.align == align::numeric) + fmt_specs.align = align::right; + write(this->out, static_cast(value), fmt_specs); } template ::value)> - auto operator()(T value) -> OutputIt { - return base::operator()(value); + void operator()(T value) { + base::operator()(value); } /** Formats a null-terminated C string. */ - auto operator()(const char* value) -> OutputIt { - if (value) return base::operator()(value); - return write_null_pointer(this->specs.type != presentation_type::pointer); + void operator()(const char* value) { + if (value) + base::operator()(value); + else + write_null_pointer(this->specs.type != presentation_type::pointer); } /** Formats a null-terminated wide C string. */ - auto operator()(const wchar_t* value) -> OutputIt { - if (value) return base::operator()(value); - return write_null_pointer(this->specs.type != presentation_type::pointer); + void operator()(const wchar_t* value) { + if (value) + base::operator()(value); + else + write_null_pointer(this->specs.type != presentation_type::pointer); } - auto operator()(basic_string_view value) -> OutputIt { - return base::operator()(value); - } + void operator()(basic_string_view value) { base::operator()(value); } /** Formats a pointer. */ - auto operator()(const void* value) -> OutputIt { - return value ? base::operator()(value) : write_null_pointer(); + void operator()(const void* value) { + if (value) + base::operator()(value); + else + write_null_pointer(); } /** Formats an argument of a custom (user-defined) type. */ - auto operator()(typename basic_format_arg::handle handle) - -> OutputIt { - auto parse_ctx = - basic_format_parse_context(basic_string_view()); + void operator()(typename basic_format_arg::handle handle) { + auto parse_ctx = basic_format_parse_context({}); handle.format(parse_ctx, context_); - return this->out; } }; @@ -549,8 +551,7 @@ void vprintf(buffer& buf, basic_string_view format, start = it; // Format argument. - out = visit_format_arg( - printf_arg_formatter(out, specs, context), arg); + visit_format_arg(printf_arg_formatter(out, specs, context), arg); } write(out, basic_string_view(start, to_unsigned(it - start))); }