From 02a6fe59fb9042083b2dfa4899b28c5d19480110 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 9 May 2020 12:56:35 -0700 Subject: [PATCH] Named arguments go brrr --- include/fmt/core.h | 31 ++++++++++--------------------- include/fmt/format.h | 1 - test/format | 1 - 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index f2802362..15364f5d 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -814,7 +814,6 @@ template constexpr size_t count_named_args() { enum class type { none_type, - named_arg_type, // DEPRECATED // Integer types should go first, int_type, uint_type, @@ -1085,7 +1084,7 @@ using mapped_type_constant = type_constant().map(std::declval())), typename Context::char_type>; -enum { packed_arg_bits = 5 }; +enum { packed_arg_bits = 4 }; // Maximum number of arguments with packed types. enum { max_packed_args = 62 / packed_arg_bits }; enum : unsigned long long { is_unpacked_bit = 1ULL << 63 }; @@ -1160,9 +1159,6 @@ FMT_CONSTEXPR auto visit_format_arg(Visitor&& vis, switch (arg.type_) { case internal::type::none_type: break; - case internal::type::named_arg_type: - FMT_ASSERT(false, "invalid argument type"); - break; case internal::type::int_type: return vis(arg.value_.int_value); case internal::type::uint_type: @@ -1655,19 +1651,6 @@ template class basic_format_args { basic_format_args(unsigned long long desc, const format_arg* args) : desc_(desc), args_(args) {} - format_arg do_get(int index) const { - format_arg arg; - if (!is_packed()) { - if (index < max_size()) arg = args_[index]; - return arg; - } - if (index >= internal::max_packed_args) return arg; - arg.type_ = type(index); - if (arg.type_ == internal::type::none_type) return arg; - arg.value_ = values_[index]; - return arg; - } - public: basic_format_args() : desc_(0) {} @@ -1700,9 +1683,15 @@ template class basic_format_args { /** Returns the argument with the specified id. */ format_arg get(int id) const { - format_arg arg = do_get(id); - if (arg.type_ == internal::type::named_arg_type) - arg = arg.value_.named_arg->template deserialize(); + format_arg arg; + if (!is_packed()) { + if (id < max_size()) arg = args_[id]; + return arg; + } + if (id >= internal::max_packed_args) return arg; + arg.type_ = type(id); + if (arg.type_ == internal::type::none_type) return arg; + arg.value_ = values_[id]; return arg; } diff --git a/include/fmt/format.h b/include/fmt/format.h index 23cabf3e..2592bff1 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2919,7 +2919,6 @@ struct formatter