From a5f4d9820ca523322ca41c36f73ecd510b53e805 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 1 Sep 2024 21:41:45 -0700 Subject: [PATCH] Simplify arg_mapper --- include/fmt/base.h | 98 +++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 54 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index f9fd350d..6c722ef8 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -260,13 +260,6 @@ # endif #endif -// GCC < 5 requires this-> in decltype. -#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500 -# define FMT_DECLTYPE_THIS this-> -#else -# define FMT_DECLTYPE_THIS -#endif - #if FMT_MSC_VERSION # define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__)) # define FMT_UNCHECKED_ITERATOR(It) \ @@ -903,26 +896,24 @@ struct unformattable_pointer : unformattable {}; template struct arg_mapper { using char_type = typename Context::char_type; - FMT_MAP_API auto map(signed char val) -> int { return val; } - FMT_MAP_API auto map(unsigned char val) -> unsigned { return val; } - FMT_MAP_API auto map(short val) -> int { return val; } - FMT_MAP_API auto map(unsigned short val) -> unsigned { return val; } - FMT_MAP_API auto map(int val) -> int { return val; } - FMT_MAP_API auto map(unsigned val) -> unsigned { return val; } - FMT_MAP_API auto map(long val) -> long_type { return val; } - FMT_MAP_API auto map(unsigned long val) -> ulong_type { return val; } - FMT_MAP_API auto map(long long val) -> long long { return val; } - FMT_MAP_API auto map(unsigned long long val) -> unsigned long long { - return val; - } - FMT_MAP_API auto map(int128_opt val) -> int128_opt { return val; } - FMT_MAP_API auto map(uint128_opt val) -> uint128_opt { return val; } - FMT_MAP_API auto map(bool val) -> bool { return val; } + FMT_MAP_API auto map(signed char x) -> int { return x; } + FMT_MAP_API auto map(unsigned char x) -> unsigned { return x; } + FMT_MAP_API auto map(short x) -> int { return x; } + FMT_MAP_API auto map(unsigned short x) -> unsigned { return x; } + FMT_MAP_API auto map(int x) -> int { return x; } + FMT_MAP_API auto map(unsigned x) -> unsigned { return x; } + FMT_MAP_API auto map(long x) -> long_type { return x; } + FMT_MAP_API auto map(unsigned long x) -> ulong_type { return x; } + FMT_MAP_API auto map(long long x) -> long long { return x; } + FMT_MAP_API auto map(unsigned long long x) -> unsigned long long { return x; } + FMT_MAP_API auto map(int128_opt x) -> int128_opt { return x; } + FMT_MAP_API auto map(uint128_opt x) -> uint128_opt { return x; } + FMT_MAP_API auto map(bool x) -> bool { return x; } template ::value || std::is_same::value)> - FMT_MAP_API auto map(T val) -> char_type { - return val; + FMT_MAP_API auto map(T x) -> char_type { + return x; } template ::value || #ifdef __cpp_char8_t @@ -936,43 +927,43 @@ template struct arg_mapper { return {}; } - FMT_MAP_API auto map(float val) -> float { return val; } - FMT_MAP_API auto map(double val) -> double { return val; } - FMT_MAP_API auto map(long double val) -> long double { return val; } + FMT_MAP_API auto map(float x) -> float { return x; } + FMT_MAP_API auto map(double x) -> double { return x; } + FMT_MAP_API auto map(long double x) -> long double { return x; } template ::is_formattable)> - FMT_MAP_API auto map(T val) -> typename bitint_traits::format_type { - return val; + FMT_MAP_API auto map(T x) -> typename bitint_traits::format_type { + return x; } template ::is_formattable)> FMT_MAP_API auto map(T) -> unformattable { return {}; } - FMT_MAP_API auto map(char_type* val) -> const char_type* { return val; } - FMT_MAP_API auto map(const char_type* val) -> const char_type* { return val; } - template , - FMT_ENABLE_IF(std::is_same::value && + FMT_MAP_API auto map(char_type* x) -> const char_type* { return x; } + FMT_MAP_API auto map(const char_type* x) -> const char_type* { return x; } + template , + FMT_ENABLE_IF(std::is_same::value && !std::is_pointer::value)> - FMT_MAP_API auto map(const T& val) -> basic_string_view { - return to_string_view(val); + FMT_MAP_API auto map(const T& x) -> basic_string_view { + return to_string_view(x); } - template , - FMT_ENABLE_IF(!std::is_same::value && + template , + FMT_ENABLE_IF(!std::is_same::value && !std::is_pointer::value)> FMT_MAP_API auto map(const T&) -> unformattable_char { return {}; } - FMT_MAP_API auto map(void* val) -> const void* { return val; } - FMT_MAP_API auto map(const void* val) -> const void* { return val; } - FMT_MAP_API auto map(volatile void* val) -> const void* { - return const_cast(val); + FMT_MAP_API auto map(void* x) -> const void* { return x; } + FMT_MAP_API auto map(const void* x) -> const void* { return x; } + FMT_MAP_API auto map(volatile void* x) -> const void* { + return const_cast(x); } - FMT_MAP_API auto map(const volatile void* val) -> const void* { - return const_cast(val); + FMT_MAP_API auto map(const volatile void* x) -> const void* { + return const_cast(x); } - FMT_MAP_API auto map(std::nullptr_t val) -> const void* { return val; } + 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. @@ -989,15 +980,15 @@ template struct arg_mapper { template ::value)> - FMT_MAP_API auto map(const T (&values)[N]) -> const T (&)[N] { - return values; + FMT_MAP_API auto map(const T (&x)[N]) -> const T (&)[N] { + return x; } // Only map owning types because mapping views can be unsafe. template , FMT_ENABLE_IF(std::is_arithmetic::value)> - FMT_MAP_API auto map(const T& val) -> decltype(FMT_DECLTYPE_THIS map(U())) { - return map(format_as(val)); + FMT_MAP_API auto map(const T& x) -> decltype(map(U())) { + return map(format_as(x)); } template > @@ -1007,8 +998,8 @@ template struct arg_mapper { !std::is_const::value)> {}; template ::value)> - FMT_MAP_API auto do_map(T& val) -> T& { - return val; + FMT_MAP_API auto do_map(T& x) -> T& { + return x; } template ::value)> FMT_MAP_API auto do_map(T&) -> unformattable { @@ -1023,13 +1014,12 @@ template struct arg_mapper { !has_to_string_view::value && !is_char::value && !is_named_arg::value && !std::is_integral::value && !std::is_arithmetic>::value)> - FMT_MAP_API auto map(T& val) -> decltype(FMT_DECLTYPE_THIS do_map(val)) { - return do_map(val); + FMT_MAP_API auto map(T& x) -> decltype(do_map(x)) { + return do_map(x); } template ::value)> - FMT_MAP_API auto map(const T& named_arg) - -> decltype(FMT_DECLTYPE_THIS map(named_arg.value)) { + FMT_MAP_API auto map(const T& named_arg) -> decltype(map(named_arg.value)) { return map(named_arg.value); }