mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-05 00:40:12 +00:00
Make value the second argument to format_value
This commit is contained in:
parent
edf98792a5
commit
b656a1c133
16
fmt/format.h
16
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 <typename Formatter, typename Char, typename T>
|
||||
void format_value(BasicWriter<Char> &, Formatter &, const Char *, const T &) {
|
||||
template <typename Formatter, typename T, typename Char>
|
||||
void format_value(BasicWriter<Char> &, const T &, Formatter &, const Char *) {
|
||||
FMT_STATIC_ASSERT(False<T>::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 <typename T>
|
||||
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<typename Formatter::char_type> Writer;
|
||||
format_value(*static_cast<Writer*>(writer),
|
||||
*static_cast<const T*>(arg),
|
||||
*static_cast<Formatter*>(formatter),
|
||||
*static_cast<const Char**>(format_str_ptr),
|
||||
*static_cast<const T*>(arg));
|
||||
*static_cast<const Char**>(format_str_ptr));
|
||||
}
|
||||
|
||||
public:
|
||||
@ -2180,7 +2180,7 @@ class BasicArgFormatter : public internal::ArgFormatterBase<Impl, Char> {
|
||||
|
||||
/** 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<Char, ArgFormatter>::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;
|
||||
|
@ -83,8 +83,9 @@ BasicStringRef<Char> format_value(
|
||||
|
||||
// Formats a value.
|
||||
template <typename Char, typename ArgFormatter, typename T>
|
||||
void format_value(BasicWriter<Char> &w, basic_formatter<Char, ArgFormatter> &f,
|
||||
const Char *&format_str, const T &value) {
|
||||
void format_value(BasicWriter<Char> &w, const T &value,
|
||||
basic_formatter<Char, ArgFormatter> &f,
|
||||
const Char *&format_str) {
|
||||
internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer;
|
||||
auto str = internal::format_value(buffer, value);
|
||||
typedef internal::MakeArg< basic_formatter<Char> > MakeArg;
|
||||
|
@ -266,7 +266,7 @@ class BasicPrintfArgFormatter : public internal::ArgFormatterBase<Impl, Char> {
|
||||
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<Char, AF>::format(BasicCStringRef<Char> format_str) {
|
||||
|
||||
// Formats a value.
|
||||
template <typename Char, typename T>
|
||||
void format_value(BasicWriter<Char> &w, PrintfFormatter<Char> &f,
|
||||
const Char *&, const T &value) {
|
||||
void format_value(BasicWriter<Char> &w, const T &value,
|
||||
PrintfFormatter<Char> &f, const Char *&) {
|
||||
internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer;
|
||||
f.writer() << internal::format_value(buffer, value);
|
||||
}
|
||||
|
@ -16,8 +16,9 @@
|
||||
namespace fmt {
|
||||
|
||||
template <typename ArgFormatter>
|
||||
void format_value(Writer &w, basic_formatter<char, ArgFormatter> &f,
|
||||
const char *&format_str, const std::tm &tm) {
|
||||
void format_value(Writer &w, const std::tm &tm,
|
||||
basic_formatter<char, ArgFormatter> &f,
|
||||
const char *&format_str) {
|
||||
if (*format_str == ':')
|
||||
++format_str;
|
||||
const char *end = format_str;
|
||||
|
@ -1355,8 +1355,8 @@ TEST(FormatterTest, FormatCStringRef) {
|
||||
EXPECT_EQ("test", format("{0}", CStringRef("test")));
|
||||
}
|
||||
|
||||
void format_value(fmt::Writer &w, fmt::basic_formatter<char> &f,
|
||||
const char *, const Date &d) {
|
||||
void format_value(fmt::Writer &w, const Date &d, fmt::basic_formatter<char> &f,
|
||||
const char *) {
|
||||
f.writer() << d.year() << '-' << d.month() << '-' << d.day();
|
||||
}
|
||||
|
||||
@ -1369,8 +1369,8 @@ TEST(FormatterTest, FormatCustom) {
|
||||
class Answer {};
|
||||
|
||||
template <typename Char>
|
||||
void format_value(BasicWriter<Char> &w, fmt::basic_formatter<Char> &f,
|
||||
const Char *, Answer) {
|
||||
void format_value(BasicWriter<Char> &w, Answer, fmt::basic_formatter<Char> &f,
|
||||
const Char *) {
|
||||
f.writer() << "42";
|
||||
}
|
||||
|
||||
|
@ -64,8 +64,8 @@ namespace {
|
||||
struct Test {};
|
||||
|
||||
template <typename Char>
|
||||
void format_value(fmt::BasicWriter<Char> &w, fmt::basic_formatter<Char> &f,
|
||||
const Char *, Test) {
|
||||
void format_value(fmt::BasicWriter<Char> &w, Test,
|
||||
fmt::basic_formatter<Char> &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";
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user