Optimize default formatting
This commit is contained in:
@@ -19,14 +19,15 @@ class custom_arg_formatter :
|
||||
typedef fmt::back_insert_range<fmt::internal::buffer> range;
|
||||
typedef fmt::arg_formatter<range> base;
|
||||
|
||||
custom_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
|
||||
custom_arg_formatter(
|
||||
fmt::format_context &ctx, fmt::format_specs *s = FMT_NULL)
|
||||
: base(ctx, s) {}
|
||||
|
||||
using base::operator();
|
||||
|
||||
iterator operator()(double value) {
|
||||
// Comparing a float to 0.0 is safe
|
||||
if (round(value * pow(10, spec().precision())) == 0.0)
|
||||
if (round(value * pow(10, spec()->precision())) == 0.0)
|
||||
value = 0;
|
||||
return base::operator()(value);
|
||||
}
|
||||
|
||||
@@ -1471,7 +1471,7 @@ class mock_arg_formatter:
|
||||
typedef fmt::internal::arg_formatter_base<buffer_range> base;
|
||||
typedef buffer_range range;
|
||||
|
||||
mock_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
|
||||
mock_arg_formatter(fmt::format_context &ctx, fmt::format_specs *s = FMT_NULL)
|
||||
: base(fmt::internal::get_container(ctx.out()), s) {
|
||||
EXPECT_CALL(*this, call(42));
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ typedef fmt::back_insert_range<fmt::internal::buffer> range;
|
||||
|
||||
struct test_arg_formatter: fmt::arg_formatter<range> {
|
||||
test_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
|
||||
: fmt::arg_formatter<range>(ctx, s) {}
|
||||
: fmt::arg_formatter<range>(ctx, &s) {}
|
||||
};
|
||||
|
||||
TEST(OStreamTest, CustomArg) {
|
||||
|
||||
Reference in New Issue
Block a user