From b135f1c01449f6f41be3933437797e768b54295a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 9 Jun 2022 16:57:52 -0700 Subject: [PATCH] Refactor handling of argument types --- include/fmt/compile.h | 4 ++-- include/fmt/core.h | 22 ++++++---------------- test/core-test.cc | 4 ++-- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 30cb0664..c09dd6f2 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -337,8 +337,8 @@ template constexpr parse_specs_result parse_specs(basic_string_view str, size_t pos, int next_arg_id) { str.remove_prefix(pos); - auto ctx = - compile_parse_context(str, format_arg_types<10>(), {}, next_arg_id); + auto ctx = compile_parse_context(str, max_value(), nullptr, {}, + next_arg_id); auto f = formatter(); auto end = f.parse(ctx); return {f, pos + fmt::detail::to_unsigned(end - str.data()) + 1, diff --git a/include/fmt/core.h b/include/fmt/core.h index 6ca9da27..43335a47 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -597,15 +597,6 @@ constexpr bool is_arithmetic_type(type t) { return t > type::none_type && t <= type::last_numeric_type; } -template struct format_arg_types { - type types[NUM_ARGS > 0 ? NUM_ARGS : 1]; -}; - -template -constexpr format_arg_types make_format_arg_types() { - return {type_constant::value...}; -} - FMT_NORETURN FMT_API void throw_format_error(const char* message); struct error_handler { @@ -713,13 +704,10 @@ class compile_parse_context using base = basic_format_parse_context; public: - template explicit FMT_CONSTEXPR compile_parse_context( - basic_string_view format_str, const format_arg_types& t, + basic_string_view format_str, int num_args, const type* types, ErrorHandler eh = {}, int next_arg_id = 0) - : base(format_str, eh, next_arg_id), - num_args_(NUM_ARGS), - types_(t.types) {} + : base(format_str, eh, next_arg_id), num_args_(num_args), types_(types) {} constexpr int num_args() const { return num_args_; } @@ -2900,12 +2888,14 @@ class format_string_checker { parse_context_type context_; parse_func parse_funcs_[num_args > 0 ? num_args : 1]; + type types_[num_args > 0 ? num_args : 1]; public: explicit FMT_CONSTEXPR format_string_checker( basic_string_view format_str, ErrorHandler eh) - : context_(format_str, make_format_arg_types(), eh), - parse_funcs_{&parse_format_specs...} {} + : context_(format_str, num_args, types_, eh), + parse_funcs_{&parse_format_specs...}, + types_{type_constant::value...} {} FMT_CONSTEXPR void on_text(const Char*, const Char*) {} diff --git a/test/core-test.cc b/test/core-test.cc index c7f07273..ce0816c6 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -385,11 +385,11 @@ VISIT_TYPE(unsigned long, unsigned long long); template class numeric_arg_test : public testing::Test {}; -using types = +using test_types = testing::Types; -TYPED_TEST_SUITE(numeric_arg_test, types); +TYPED_TEST_SUITE(numeric_arg_test, test_types); template ::value, int> = 0> T test_value() {