From b656a1c133a0dccd8070d391ba5e80852bc6a6fb Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 25 Oct 2016 06:19:19 -0700 Subject: [PATCH] Make value the second argument to format_value --- fmt/format.h | 16 ++++++++-------- fmt/ostream.h | 5 +++-- fmt/printf.h | 6 +++--- fmt/time.h | 5 +++-- test/format-test.cc | 8 ++++---- test/util-test.cc | 8 ++++---- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/fmt/format.h b/fmt/format.h index 56347bad..8cddbd7f 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -993,7 +993,7 @@ struct Value { }; typedef void (*FormatFunc)( - void *writer, void *formatter, const void *arg, void *format_str_ptr); + void *writer, const void *arg, void *formatter, void *format_str_ptr); struct CustomValue { const void *value; @@ -1159,8 +1159,8 @@ inline fmt::StringRef thousands_sep(...) { return ""; } typedef int FMT_CONCAT_(Assert, __LINE__)[(cond) ? 1 : -1] FMT_UNUSED #endif -template -void format_value(BasicWriter &, Formatter &, const Char *, const T &) { +template +void format_value(BasicWriter &, const T &, Formatter &, const Char *) { FMT_STATIC_ASSERT(False::value, "Cannot format argument. To enable the use of ostream " "operator<< include fmt/ostream.h. Otherwise provide " @@ -1271,12 +1271,12 @@ class MakeValue : public Arg { // Formats an argument of a custom type, such as a user-defined class. template static void format_custom_arg( - void *writer, void *formatter, const void *arg, void *format_str_ptr) { + void *writer, const void *arg, void *formatter, void *format_str_ptr) { typedef BasicWriter Writer; format_value(*static_cast(writer), + *static_cast(arg), *static_cast(formatter), - *static_cast(format_str_ptr), - *static_cast(arg)); + *static_cast(format_str_ptr)); } public: @@ -2180,7 +2180,7 @@ class BasicArgFormatter : public internal::ArgFormatterBase { /** Formats an argument of a custom (user-defined) type. */ void visit_custom(internal::Arg::CustomValue c) { - c.format(&formatter_.writer(), &formatter_, c.value, &format_); + c.format(&formatter_.writer(), c.value, &formatter_, &format_); } }; @@ -3469,7 +3469,7 @@ const Char *basic_formatter::format( FormatSpec spec; if (*s == ':') { if (arg.type == Arg::CUSTOM) { - arg.custom.format(&writer(), this, arg.custom.value, &s); + arg.custom.format(&writer(), arg.custom.value, this, &s); return s; } ++s; diff --git a/fmt/ostream.h b/fmt/ostream.h index 5fee51a9..968a4100 100644 --- a/fmt/ostream.h +++ b/fmt/ostream.h @@ -83,8 +83,9 @@ BasicStringRef format_value( // Formats a value. template -void format_value(BasicWriter &w, basic_formatter &f, - const Char *&format_str, const T &value) { +void format_value(BasicWriter &w, const T &value, + basic_formatter &f, + const Char *&format_str) { internal::MemoryBuffer buffer; auto str = internal::format_value(buffer, value); typedef internal::MakeArg< basic_formatter > MakeArg; diff --git a/fmt/printf.h b/fmt/printf.h index 1635396e..cf9a8517 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -266,7 +266,7 @@ class BasicPrintfArgFormatter : public internal::ArgFormatterBase { this->writer()); const Char format_str[] = {'}', 0}; const Char *format = format_str; - c.format(&formatter.writer(), &formatter, c.value, &format); + c.format(&formatter.writer(), c.value, &formatter, &format); } }; @@ -497,8 +497,8 @@ void PrintfFormatter::format(BasicCStringRef format_str) { // Formats a value. template -void format_value(BasicWriter &w, PrintfFormatter &f, - const Char *&, const T &value) { +void format_value(BasicWriter &w, const T &value, + PrintfFormatter &f, const Char *&) { internal::MemoryBuffer buffer; f.writer() << internal::format_value(buffer, value); } diff --git a/fmt/time.h b/fmt/time.h index bb12a66f..5b40a93f 100644 --- a/fmt/time.h +++ b/fmt/time.h @@ -16,8 +16,9 @@ namespace fmt { template -void format_value(Writer &w, basic_formatter &f, - const char *&format_str, const std::tm &tm) { +void format_value(Writer &w, const std::tm &tm, + basic_formatter &f, + const char *&format_str) { if (*format_str == ':') ++format_str; const char *end = format_str; diff --git a/test/format-test.cc b/test/format-test.cc index 998767bf..2d4d10aa 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1355,8 +1355,8 @@ TEST(FormatterTest, FormatCStringRef) { EXPECT_EQ("test", format("{0}", CStringRef("test"))); } -void format_value(fmt::Writer &w, fmt::basic_formatter &f, - const char *, const Date &d) { +void format_value(fmt::Writer &w, const Date &d, fmt::basic_formatter &f, + const char *) { f.writer() << d.year() << '-' << d.month() << '-' << d.day(); } @@ -1369,8 +1369,8 @@ TEST(FormatterTest, FormatCustom) { class Answer {}; template -void format_value(BasicWriter &w, fmt::basic_formatter &f, - const Char *, Answer) { +void format_value(BasicWriter &w, Answer, fmt::basic_formatter &f, + const Char *) { f.writer() << "42"; } diff --git a/test/util-test.cc b/test/util-test.cc index d27d2a3f..33603340 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -64,8 +64,8 @@ namespace { struct Test {}; template -void format_value(fmt::BasicWriter &w, fmt::basic_formatter &f, - const Char *, Test) { +void format_value(fmt::BasicWriter &w, Test, + fmt::basic_formatter &f, const Char *) { w << "test"; } @@ -582,8 +582,8 @@ struct CustomFormatter { typedef char char_type; }; -void format_value(fmt::Writer &, CustomFormatter &, const char *&s, - const Test &) { +void format_value(fmt::Writer &, const Test &, CustomFormatter &, + const char *&s) { s = "custom_format"; }