From 822eccc3b84f7cd91c8435b0c090e49d2eafe96c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 21 Apr 2018 14:29:24 -0700 Subject: [PATCH] Sync API with standards proposal --- include/fmt/core.h | 13 +++++-------- include/fmt/format.h | 4 ++-- test/util-test.cc | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 8fc4f8e3..df9a5242 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -686,7 +686,7 @@ class basic_format_arg { public: explicit handle(internal::custom_value custom): custom_(custom) {} - void format(Context &ctx) { custom_.format(custom_.value, ctx); } + void format(Context &ctx) const { custom_.format(custom_.value, ctx); } private: internal::custom_value custom_; @@ -702,7 +702,6 @@ class basic_format_arg { bool is_integral() const { return internal::is_integral(type_); } bool is_arithmetic() const { return internal::is_arithmetic(type_); } - bool is_pointer() const { return type_ == internal::pointer_type; } }; // Parsing context consisting of a format string range being parsed and an @@ -816,7 +815,7 @@ class context_base { // Returns the argument with specified index. format_arg do_get_arg(unsigned arg_id) { - format_arg arg = args_[arg_id]; + format_arg arg = args_.get(arg_id); if (!arg) parse_context_.on_error("argument index out of range"); return arg; @@ -986,8 +985,6 @@ class format_arg_store { format_arg_store(const Args &... args) : data_{internal::make_arg(args)...} {} #endif - - basic_format_args operator*() const { return *this; } }; template @@ -1047,7 +1044,7 @@ class basic_format_args { void set_data(const internal::value *values) { values_ = values; } void set_data(const format_arg *args) { args_ = args; } - format_arg get(size_type index) const { + format_arg do_get(size_type index) const { int64_t signed_types = static_cast(types_); if (signed_types < 0) { uint64_t num_args = -signed_types; @@ -1079,8 +1076,8 @@ class basic_format_args { } /** Returns the argument at specified index. */ - format_arg operator[](size_type index) const { - format_arg arg = get(index); + format_arg get(size_type index) const { + format_arg arg = do_get(index); return arg.type_ == internal::name_arg_type ? arg.value_.as_named_arg().template deserialize() : arg; } diff --git a/include/fmt/format.h b/include/fmt/format.h index dab1c258..3372fc85 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3384,7 +3384,7 @@ template inline OutputIt format_to(OutputIt out, string_view format_str, const Args & ... args) { return vformat_to(out, format_str, - *make_format_args::type>(args...)); + make_format_args::type>(args...)); } template @@ -3415,7 +3415,7 @@ inline format_to_n_result format_to_n( OutputIt out, std::size_t n, string_view format_str, const Args & ... args) { typedef internal::truncating_iterator It; auto it = vformat_to(It(out, n), format_str, - *make_format_args::type>(args...)); + make_format_args::type>(args...)); return {it.base(), it.count()}; } diff --git a/test/util-test.cc b/test/util-test.cc index 54e6eebb..3c1da773 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -412,7 +412,7 @@ TEST(UtilTest, Increment) { TEST(UtilTest, FormatArgs) { fmt::format_args args; - EXPECT_FALSE(args[1]); + EXPECT_FALSE(args.get(1)); } struct custom_context {