From 1e938dda200e8f262bfbec31e291d639c9bb3c38 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 5 Jan 2024 08:47:50 -0800 Subject: [PATCH] Simplify char_t --- include/fmt/core.h | 36 +++++++++++++++--------------------- include/fmt/xchar.h | 9 +++++++-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 30957db0..4a83cdaf 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -412,10 +412,9 @@ FMT_CONSTEXPR auto to_unsigned(Int value) -> return static_cast::type>(value); } +// A heuristic to detect std::string and std::[experimental::]string_view. template struct is_string_like : std::false_type {}; - -// A heuristic to detect std::string and std::string_view. template struct is_string_like().find_first_of( typename T::value_type(), 0))>> : std::true_type { @@ -570,9 +569,9 @@ template <> struct is_char : std::true_type {}; namespace detail { -// Constructs fmt::basic_string_view from types **implicitly** convertible -// to it, deducing Char. Explicitly convertible types such as compile-time -// strings are intentionally excluded. +// Constructs fmt::basic_string_view from types implicitly convertible +// to it, deducing Char. Explicitly convertible types such as the ones returned +// from FMT_STRING are intentionally excluded. template ::value)> FMT_INLINE auto to_string_view(const Char* s) -> basic_string_view { return s; @@ -597,12 +596,6 @@ template struct is_string : std::is_class()))> {}; -template struct char_t_impl {}; -template struct char_t_impl::value>> { - using result = decltype(to_string_view(std::declval())); - using type = typename result::value_type; -}; - enum class type { none_type, // Integer types should go first, @@ -681,8 +674,10 @@ enum { /** Throws ``format_error`` with a given message. */ FMT_NORETURN FMT_API void throw_format_error(const char* message); -/** String's character type. */ -template using char_t = typename detail::char_t_impl::type; +/** String's character (code unit) type. */ +template ()))> +using char_t = typename V::value_type; /** \rst @@ -1422,16 +1417,15 @@ template struct arg_mapper { FMT_CONSTEXPR FMT_INLINE auto map(const char_type* val) -> const char_type* { return val; } - template ::value && !std::is_pointer::value && - std::is_same>::value)> - FMT_CONSTEXPR FMT_INLINE auto map(const T& val) - -> basic_string_view { + template , + FMT_ENABLE_IF(std::is_same::value && + !std::is_pointer::value)> + FMT_CONSTEXPR FMT_INLINE auto map(const T& val) -> basic_string_view { return to_string_view(val); } - template ::value && !std::is_pointer::value && - !std::is_same>::value)> + template , + FMT_ENABLE_IF(!std::is_same::value && + !std::is_pointer::value)> FMT_CONSTEXPR FMT_INLINE auto map(const T&) -> unformattable_char { return {}; } diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 5b8254b7..01d2fda7 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -30,8 +30,13 @@ enum char8_type : unsigned char {}; template using is_exotic_char = bool_constant::value>; -template -struct format_string_char : char_t_impl {}; +template struct format_string_char {}; + +template +struct format_string_char< + S, void_t())))>> { + using type = char_t; +}; template struct format_string_char::value>> {