Simplify arg_formatter
This commit is contained in:
@@ -18,10 +18,9 @@
|
||||
// A custom argument formatter that doesn't print `-` for floating-point values
|
||||
// rounded to 0.
|
||||
class custom_arg_formatter
|
||||
: public fmt::arg_formatter<fmt::buffer_range<char>> {
|
||||
: public fmt::arg_formatter<fmt::format_context::iterator, char> {
|
||||
public:
|
||||
using range = fmt::buffer_range<char>;
|
||||
typedef fmt::arg_formatter<range> base;
|
||||
using base = fmt::arg_formatter<fmt::format_context::iterator, char>;
|
||||
|
||||
custom_arg_formatter(fmt::format_context& ctx,
|
||||
fmt::format_parse_context* parse_ctx,
|
||||
@@ -39,8 +38,10 @@ class custom_arg_formatter
|
||||
|
||||
std::string custom_vformat(fmt::string_view format_str, fmt::format_args args) {
|
||||
fmt::memory_buffer buffer;
|
||||
fmt::internal::buffer<char>& base = buffer;
|
||||
// Pass custom argument formatter as a template arg to vwrite.
|
||||
fmt::vformat_to<custom_arg_formatter>(buffer, format_str, args);
|
||||
fmt::vformat_to<custom_arg_formatter>(std::back_inserter(base), format_str,
|
||||
args);
|
||||
return std::string(buffer.data(), buffer.size());
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -1847,7 +1847,9 @@ class mock_arg_formatter
|
||||
|
||||
static void custom_vformat(fmt::string_view format_str, fmt::format_args args) {
|
||||
fmt::memory_buffer buffer;
|
||||
fmt::vformat_to<mock_arg_formatter>(buffer, format_str, args);
|
||||
fmt::internal::buffer<char>& base = buffer;
|
||||
fmt::vformat_to<mock_arg_formatter>(std::back_inserter(base), format_str,
|
||||
args);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
|
||||
@@ -64,12 +64,13 @@ TEST(OStreamTest, Enum) {
|
||||
EXPECT_EQ(L"0", fmt::format(L"{}", unstreamable_enum()));
|
||||
}
|
||||
|
||||
using range = fmt::buffer_range<char>;
|
||||
|
||||
struct test_arg_formatter : fmt::arg_formatter<range> {
|
||||
struct test_arg_formatter
|
||||
: fmt::arg_formatter<fmt::buffer_range<char>::iterator, char> {
|
||||
fmt::format_parse_context parse_ctx;
|
||||
test_arg_formatter(fmt::format_context& ctx, fmt::format_specs& s)
|
||||
: fmt::arg_formatter<range>(ctx, &parse_ctx, &s), parse_ctx("") {}
|
||||
: fmt::arg_formatter<fmt::buffer_range<char>::iterator, char>(
|
||||
ctx, &parse_ctx, &s),
|
||||
parse_ctx("") {}
|
||||
};
|
||||
|
||||
TEST(OStreamTest, CustomArg) {
|
||||
|
||||
Reference in New Issue
Block a user