From 2d5e561a6b26f021c330a7d9cbc0470fd6125a84 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 14 Sep 2024 08:50:14 -0700 Subject: [PATCH] Cleanup argument handling --- include/fmt/base.h | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 51649328..fa41e6f2 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -595,8 +595,17 @@ template class basic_string_view { using string_view = basic_string_view; -/// Specifies if `T` is a character type. Can be specialized by users. -template struct is_char : std::false_type {}; +/// Specifies if `T` is an extended character type. Can be specialized by users. +template struct is_xchar : std::false_type {}; +template <> struct is_xchar : std::true_type {}; +template <> struct is_xchar : std::true_type {}; +template <> struct is_xchar : std::true_type {}; +#ifdef __cpp_char8_t +template <> struct is_xchar : std::true_type {}; +#endif + +// DEPRECATED! Will be replaced with an alias to prevent specializations. +template struct is_char : is_xchar {}; template <> struct is_char : std::true_type {}; template class basic_appender; @@ -1127,14 +1136,8 @@ template struct arg_mapper { FMT_MAP_API auto map(T x) -> Char { return x; } - template ::value || -#ifdef __cpp_char8_t - std::is_same::value || -#endif - std::is_same::value || - std::is_same::value) && - !std::is_same::value, - int> = 0> + template ::value && !std::is_same::value)> FMT_MAP_API auto map(T) -> unformattable_char { return {}; } @@ -1185,15 +1188,12 @@ template struct arg_mapper { } FMT_MAP_API auto map(std::nullptr_t x) -> const void* { return x; } - // Use SFINAE instead of a const T* parameter to avoid a conflict with the - // array overload. template < - typename T, + typename T, typename Element = typename std::remove_extent::type, FMT_ENABLE_IF( std::is_pointer::value || std::is_member_pointer::value || std::is_function::type>::value || - (std::is_array::value && - !std::is_convertible::value))> + (std::is_array::value && !is_char::value))> FMT_MAP_API auto map(const T&) -> unformattable_pointer { return {}; } @@ -2182,8 +2182,9 @@ template class value { constexpr FMT_INLINE value(bool x FMT_BUILTIN) : bool_value(x) {} template ::value)> constexpr FMT_INLINE value(T x FMT_BUILTIN) : char_value(x) { - static_assert(std::is_same::value, - "mixing character types is disallowed"); + static_assert( + std::is_same::value || std::is_same::value, + "mixing character types is disallowed"); } FMT_CONSTEXPR FMT_INLINE value(const char_type* x FMT_BUILTIN) { string.data = x;