mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-06 04:50:05 +00:00
Implement a workaround for older GCC.
This commit is contained in:
parent
74494c29cb
commit
b09f371306
24
format.h
24
format.h
@ -811,6 +811,15 @@ void Format(BasicWriter<Char> &f, const FormatSpec &spec, const T &value) {
|
|||||||
f.Write(os.str(), spec);
|
f.Write(os.str(), spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
// Formats an argument of a custom type, such as a user-defined class.
|
||||||
|
template <typename Char, typename T>
|
||||||
|
void FormatCustomArg(
|
||||||
|
BasicWriter<Char> &w, const void *arg, const FormatSpec &spec) {
|
||||||
|
Format(w, spec, *static_cast<const T*>(arg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
The :cpp:class:`fmt::BasicFormatter` template provides string formatting
|
The :cpp:class:`fmt::BasicFormatter` template provides string formatting
|
||||||
@ -845,8 +854,8 @@ class BasicFormatter : public BasicWriter<Char> {
|
|||||||
CHAR, STRING, WSTRING, POINTER, CUSTOM
|
CHAR, STRING, WSTRING, POINTER, CUSTOM
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (BasicFormatter::*FormatFunc)(
|
typedef void (*FormatFunc)(
|
||||||
const void *arg, const FormatSpec &spec);
|
BasicWriter<Char> &w, const void *arg, const FormatSpec &spec);
|
||||||
|
|
||||||
// A format argument.
|
// A format argument.
|
||||||
class Arg {
|
class Arg {
|
||||||
@ -919,7 +928,7 @@ class BasicFormatter : public BasicWriter<Char> {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
Arg(const T &value) : type(CUSTOM), formatter(0) {
|
Arg(const T &value) : type(CUSTOM), formatter(0) {
|
||||||
custom.value = &value;
|
custom.value = &value;
|
||||||
custom.format = &BasicFormatter<Char>::FormatCustomArg<T>;
|
custom.format = &internal::FormatCustomArg<Char, T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Arg() {
|
~Arg() {
|
||||||
@ -954,13 +963,6 @@ class BasicFormatter : public BasicWriter<Char> {
|
|||||||
|
|
||||||
void ReportError(const char *s, StringRef message) const;
|
void ReportError(const char *s, StringRef message) const;
|
||||||
|
|
||||||
// Formats an argument of a custom type, such as a user-defined class.
|
|
||||||
template <typename T>
|
|
||||||
void FormatCustomArg(const void *arg, const FormatSpec &spec) {
|
|
||||||
BasicWriter<Char> &f = *this;
|
|
||||||
Format(f, spec, *static_cast<const T*>(arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned ParseUInt(const char *&s) const;
|
unsigned ParseUInt(const char *&s) const;
|
||||||
|
|
||||||
// Parses argument index and returns an argument with this index.
|
// Parses argument index and returns an argument with this index.
|
||||||
@ -1514,7 +1516,7 @@ void BasicFormatter<Char>::DoFormat() {
|
|||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
if (spec.type_)
|
if (spec.type_)
|
||||||
internal::ReportUnknownType(spec.type_, "object");
|
internal::ReportUnknownType(spec.type_, "object");
|
||||||
(this->*arg.custom.format)(arg.custom.value, spec);
|
arg.custom.format(*this, arg.custom.value, spec);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user