From 87fbc6f7566e4d3266bd3a2cd69f6c90e1aefa5d Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 10 Jun 2019 21:21:45 -0700 Subject: [PATCH] get_type -> mapped_type_constant --- include/fmt/core.h | 16 +++++++++------- include/fmt/format.h | 3 ++- test/core-test.cc | 13 ++++++++----- test/format | 2 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index b2873740..4389ee16 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -827,6 +827,12 @@ template struct arg_mapper { } }; +// A type constant after applying arg_mapper. +template +using mapped_type_constant = + type_constant().map(std::declval())), + typename Context::char_type>; + // Maximum number of arguments with packed types. enum { max_packed_args = 15 }; enum : unsigned long long { is_unpacked_bit = 1ull << 63 }; @@ -983,22 +989,18 @@ class locale_ref { template Locale get() const; }; -template -using get_type = - type_constant().map(std::declval())), - typename Context::char_type>; - template constexpr unsigned long long get_types() { return 0; } template constexpr unsigned long long get_types() { - return get_type::value | (get_types() << 4); + return mapped_type_constant::value | + (get_types() << 4); } template FMT_CONSTEXPR basic_format_arg make_arg(const T& value) { basic_format_arg arg; - arg.type_ = get_type::value; + arg.type_ = mapped_type_constant::value; arg.value_ = arg_mapper().map(value); return arg; } diff --git a/include/fmt/format.h b/include/fmt/format.h index b1b98cd4..1c257b1d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3165,7 +3165,8 @@ template class dynamic_formatter { auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) { handle_specs(ctx); internal::specs_checker checker( - null_handler(), internal::get_type::value); + null_handler(), + internal::mapped_type_constant::value); checker.on_align(specs_.align()); if (specs_.flags == 0) ; // Do nothing. diff --git a/test/core-test.cc b/test/core-test.cc index 84713de8..0de26dbe 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -567,15 +567,18 @@ TEST(CoreTest, ToStringViewForeignStrings) { EXPECT_EQ(to_string_view(my_string(L"42")), L"42"); EXPECT_EQ(to_string_view(QString(L"42")), L"42"); fmt::internal::type type = - fmt::internal::get_type>::value; + fmt::internal::mapped_type_constant, + fmt::format_context>::value; + EXPECT_EQ(type, fmt::internal::string_type); + type = fmt::internal::mapped_type_constant, + fmt::wformat_context>::value; EXPECT_EQ(type, fmt::internal::string_type); type = - fmt::internal::get_type>::value; - EXPECT_EQ(type, fmt::internal::string_type); - type = fmt::internal::get_type::value; + fmt::internal::mapped_type_constant::value; EXPECT_EQ(type, fmt::internal::string_type); // Does not compile: only wide format contexts are compatible with QString! - // type = fmt::internal::get_type::value; + // type = fmt::internal::mapped_type_constant::value; } TEST(CoreTest, FormatForeignStrings) { diff --git a/test/format b/test/format index 3f9f2f92..53a7b5df 100644 --- a/test/format +++ b/test/format @@ -643,7 +643,7 @@ struct formatter { FMT_CONSTEXPR typename ParseContext::iterator parse(ParseContext& ctx) { namespace internal = fmt::internal; typedef internal::dynamic_specs_handler handler_type; - auto type = internal::get_type, T>::value; + auto type = internal::mapped_type_constant>::value; internal::specs_checker handler(handler_type(specs_, ctx), type); auto it = parse_format_specs(ctx.begin(), ctx.end(), handler);