Spec template argument defaulted to FormatSpec
This commit is contained in:
parent
cf78fb2745
commit
1e6edbc9b5
@ -120,19 +120,17 @@ custom argument formatter class::
|
||||
// A custom argument formatter that formats negative integers as unsigned
|
||||
// with the ``x`` format specifier.
|
||||
class CustomArgFormatter :
|
||||
public fmt::BasicArgFormatter<CustomArgFormatter, char, fmt::FormatSpec> {
|
||||
public fmt::BasicArgFormatter<CustomArgFormatter, char> {
|
||||
public:
|
||||
CustomArgFormatter(fmt::BasicFormatter<char, CustomArgFormatter> &f,
|
||||
fmt::FormatSpec &s, const char *fmt)
|
||||
: fmt::BasicArgFormatter<CustomArgFormatter, char,
|
||||
fmt::FormatSpec>(f, s, fmt) {}
|
||||
: fmt::BasicArgFormatter<CustomArgFormatter, char>(f, s, fmt) {}
|
||||
|
||||
void visit_int(int value) {
|
||||
if (spec().type() == 'x')
|
||||
visit_uint(value); // convert to unsigned and format
|
||||
else
|
||||
fmt::BasicArgFormatter<CustomArgFormatter, char,
|
||||
fmt::FormatSpec>::visit_int(value);
|
||||
fmt::BasicArgFormatter<CustomArgFormatter, char>::visit_int(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -431,7 +431,7 @@ typedef BasicWriter<wchar_t> WWriter;
|
||||
template <typename Char>
|
||||
class ArgFormatter;
|
||||
|
||||
template <typename Impl, typename Char, typename Spec>
|
||||
template <typename Impl, typename Char, typename Spec = fmt::FormatSpec>
|
||||
class BasicPrintfArgFormatter;
|
||||
|
||||
template <typename CharType,
|
||||
@ -1925,7 +1925,7 @@ class ArgMap {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Impl, typename Char, typename Spec>
|
||||
template <typename Impl, typename Char, typename Spec = fmt::FormatSpec>
|
||||
class ArgFormatterBase : public ArgVisitor<Impl, void> {
|
||||
private:
|
||||
BasicWriter<Char> &writer_;
|
||||
@ -2091,7 +2091,7 @@ class FormatterBase {
|
||||
will be called.
|
||||
\endrst
|
||||
*/
|
||||
template <typename Impl, typename Char, typename Spec>
|
||||
template <typename Impl, typename Char, typename Spec = fmt::FormatSpec>
|
||||
class BasicArgFormatter : public internal::ArgFormatterBase<Impl, Char, Spec> {
|
||||
private:
|
||||
BasicFormatter<Char, Impl> &formatter_;
|
||||
|
||||
@ -15,29 +15,25 @@ using fmt::BasicPrintfArgFormatter;
|
||||
// A custom argument formatter that doesn't print `-` for floating-point values
|
||||
// rounded to 0.
|
||||
class CustomArgFormatter :
|
||||
public fmt::BasicArgFormatter<CustomArgFormatter, char, fmt::FormatSpec> {
|
||||
public fmt::BasicArgFormatter<CustomArgFormatter, char> {
|
||||
public:
|
||||
CustomArgFormatter(fmt::BasicFormatter<char, CustomArgFormatter> &f,
|
||||
fmt::FormatSpec &s, const char *fmt)
|
||||
: fmt::BasicArgFormatter<CustomArgFormatter, char,
|
||||
fmt::FormatSpec>(f, s, fmt) {}
|
||||
: fmt::BasicArgFormatter<CustomArgFormatter, char>(f, s, fmt) {}
|
||||
|
||||
void visit_double(double value) {
|
||||
if (round(value * pow(10, spec().precision())) == 0)
|
||||
value = 0;
|
||||
fmt::BasicArgFormatter<CustomArgFormatter, char,
|
||||
fmt::FormatSpec>::visit_double(value);
|
||||
fmt::BasicArgFormatter<CustomArgFormatter, char>::visit_double(value);
|
||||
}
|
||||
};
|
||||
|
||||
// A custom argument formatter that doesn't print `-` for floating-point values
|
||||
// rounded to 0.
|
||||
class CustomPrintfArgFormatter :
|
||||
public BasicPrintfArgFormatter<CustomPrintfArgFormatter, char,
|
||||
fmt::FormatSpec> {
|
||||
public BasicPrintfArgFormatter<CustomPrintfArgFormatter, char> {
|
||||
public:
|
||||
typedef BasicPrintfArgFormatter<CustomPrintfArgFormatter, char,
|
||||
fmt::FormatSpec> Base;
|
||||
typedef BasicPrintfArgFormatter<CustomPrintfArgFormatter, char> Base;
|
||||
|
||||
CustomPrintfArgFormatter(fmt::BasicWriter<char> &w, fmt::FormatSpec &spec)
|
||||
: Base(w, spec) {}
|
||||
|
||||
@ -1630,16 +1630,13 @@ TEST(FormatTest, Enum) {
|
||||
}
|
||||
|
||||
class MockArgFormatter :
|
||||
public fmt::internal::ArgFormatterBase<MockArgFormatter, char,
|
||||
fmt::FormatSpec> {
|
||||
public fmt::internal::ArgFormatterBase<MockArgFormatter, char> {
|
||||
public:
|
||||
typedef fmt::internal::ArgFormatterBase<MockArgFormatter, char,
|
||||
fmt::FormatSpec> Base;
|
||||
typedef fmt::internal::ArgFormatterBase<MockArgFormatter, char> Base;
|
||||
|
||||
MockArgFormatter(fmt::BasicFormatter<char, MockArgFormatter> &f,
|
||||
fmt::FormatSpec &s, const char *)
|
||||
: fmt::internal::ArgFormatterBase<MockArgFormatter,
|
||||
char, fmt::FormatSpec>(f.writer(), s) {
|
||||
: fmt::internal::ArgFormatterBase<MockArgFormatter, char>(f.writer(), s) {
|
||||
EXPECT_CALL(*this, visit_int(42));
|
||||
}
|
||||
|
||||
@ -1663,4 +1660,3 @@ void convert(int);
|
||||
TEST(FormatTest, ConvertCollision) {
|
||||
fmt::format("{}", 42);
|
||||
}
|
||||
|
||||
|
||||
@ -58,12 +58,10 @@ TEST(OStreamTest, Enum) {
|
||||
EXPECT_EQ("0", fmt::format("{}", A));
|
||||
}
|
||||
|
||||
struct TestArgFormatter :
|
||||
fmt::BasicArgFormatter<TestArgFormatter, char, fmt::FormatSpec> {
|
||||
struct TestArgFormatter : fmt::BasicArgFormatter<TestArgFormatter, char> {
|
||||
TestArgFormatter(fmt::BasicFormatter<char, TestArgFormatter> &f,
|
||||
fmt::FormatSpec &s, const char *fmt)
|
||||
: fmt::BasicArgFormatter<TestArgFormatter, char,
|
||||
fmt::FormatSpec>(f, s, fmt) {}
|
||||
: fmt::BasicArgFormatter<TestArgFormatter, char>(f, s, fmt) {}
|
||||
};
|
||||
|
||||
TEST(OStreamTest, CustomArg) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user