From b09f3713067330a5f1d6ed2bba180f2821fda0c1 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 5 Feb 2013 08:05:01 -0800 Subject: [PATCH] Implement a workaround for older GCC. --- format.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/format.h b/format.h index 6877104a..b80a862a 100644 --- a/format.h +++ b/format.h @@ -811,6 +811,15 @@ void Format(BasicWriter &f, const FormatSpec &spec, const T &value) { f.Write(os.str(), spec); } +namespace internal { +// Formats an argument of a custom type, such as a user-defined class. +template +void FormatCustomArg( + BasicWriter &w, const void *arg, const FormatSpec &spec) { + Format(w, spec, *static_cast(arg)); +} +} + /** \rst The :cpp:class:`fmt::BasicFormatter` template provides string formatting @@ -845,8 +854,8 @@ class BasicFormatter : public BasicWriter { CHAR, STRING, WSTRING, POINTER, CUSTOM }; - typedef void (BasicFormatter::*FormatFunc)( - const void *arg, const FormatSpec &spec); + typedef void (*FormatFunc)( + BasicWriter &w, const void *arg, const FormatSpec &spec); // A format argument. class Arg { @@ -919,7 +928,7 @@ class BasicFormatter : public BasicWriter { template Arg(const T &value) : type(CUSTOM), formatter(0) { custom.value = &value; - custom.format = &BasicFormatter::FormatCustomArg; + custom.format = &internal::FormatCustomArg; } ~Arg() { @@ -954,13 +963,6 @@ class BasicFormatter : public BasicWriter { void ReportError(const char *s, StringRef message) const; - // Formats an argument of a custom type, such as a user-defined class. - template - void FormatCustomArg(const void *arg, const FormatSpec &spec) { - BasicWriter &f = *this; - Format(f, spec, *static_cast(arg)); - } - unsigned ParseUInt(const char *&s) const; // Parses argument index and returns an argument with this index. @@ -1514,7 +1516,7 @@ void BasicFormatter::DoFormat() { case CUSTOM: if (spec.type_) internal::ReportUnknownType(spec.type_, "object"); - (this->*arg.custom.format)(arg.custom.value, spec); + arg.custom.format(*this, arg.custom.value, spec); break; default: assert(false);