From 3fdba04924508f5dbf684ef393ac639cb6e692c4 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 6 Jun 2019 19:06:07 -0700 Subject: [PATCH] Reduce the number of nontrivial formatter instantiations --- include/fmt/core.h | 22 ++++++++++++ include/fmt/format.h | 79 ++++++++++++++++++++++++++++++-------------- test/format-test.cc | 6 ++-- 3 files changed, 80 insertions(+), 27 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 134934d9..d3e81852 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -632,6 +632,28 @@ enum type { custom_type }; +// Maps core type T to the corresponding type enum constant. +template +struct type_constant : std::integral_constant {}; + +#define FMT_TYPE_CONSTANT(Type, constant) \ + template \ + struct type_constant : std::integral_constant {} + +FMT_TYPE_CONSTANT(int, int_type); +FMT_TYPE_CONSTANT(unsigned, uint_type); +FMT_TYPE_CONSTANT(long long, long_long_type); +FMT_TYPE_CONSTANT(unsigned long long, ulong_long_type); +FMT_TYPE_CONSTANT(bool, bool_type); +FMT_TYPE_CONSTANT(Char, char_type); +FMT_TYPE_CONSTANT(double, double_type); +FMT_TYPE_CONSTANT(long double, long_double_type); +FMT_TYPE_CONSTANT(const Char*, cstring_type); +FMT_TYPE_CONSTANT(basic_string_view, string_type); +FMT_TYPE_CONSTANT(const void*, pointer_type); + +#undef FMT_TYPE_CONSTANT + FMT_CONSTEXPR bool is_integral(type t) { FMT_ASSERT(t != internal::named_arg_type, "invalid argument type"); return t > internal::none_type && t <= internal::last_integer_type; diff --git a/include/fmt/format.h b/include/fmt/format.h index bac745b6..6bca25e4 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2179,7 +2179,7 @@ FMT_CONSTEXPR const typename ParseContext::char_type* parse_format_specs( ParseContext& ctx) { // GCC 7.2 requires initializer. typedef typename ParseContext::char_type char_type; - conditional_t::value, + conditional_t>::value, formatter, internal::fallback_formatter> f; @@ -2255,12 +2255,6 @@ void check_format_string(S format_str) { (void)invalid_format; } -// Specifies whether to format T using the standard formatter. -// It is not possible to use get_type in formatter specialization directly -// because of a bug in MSVC. -template -using format_type = bool_constant::value != custom_type>; - template