From 35c0286cd8f1365bffbc417021e8cd23112f6c8f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 2 Feb 2022 15:37:03 -0800 Subject: [PATCH] Simplify byte handling --- include/fmt/core.h | 11 ----------- include/fmt/format.h | 11 ++++++++--- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 14df573a..68b86852 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -8,7 +8,6 @@ #ifndef FMT_CORE_H_ #define FMT_CORE_H_ -#include // std::byte #include // std::FILE #include #include @@ -367,12 +366,6 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line, # endif #endif -#ifdef __cpp_lib_byte -using byte = std::byte; -#else -enum class byte : unsigned char {}; -#endif - #if defined(FMT_USE_STRING_VIEW) template using std_string_view = std::basic_string_view; #elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW) @@ -1429,10 +1422,6 @@ template struct arg_mapper { return map(format_as(val)); } - FMT_CONSTEXPR FMT_INLINE auto map(detail::byte val) -> unsigned { - return map(static_cast(val)); - } - template > struct formattable : bool_constant() || diff --git a/include/fmt/format.h b/include/fmt/format.h index d2ba7c9a..afcba52e 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -34,6 +34,7 @@ #define FMT_FORMAT_H_ #include // std::signbit +#include // std::byte #include // uint32_t #include // std::memcpy #include // std::numeric_limits @@ -159,8 +160,8 @@ FMT_END_NAMESPACE // __builtin_ctz is broken in Intel Compiler Classic on Windows: // https://github.com/fmtlib/fmt/issues/2510. #ifndef __ICL -# if FMT_HAS_BUILTIN(__builtin_ctz) || FMT_GCC_VERSION || \ - FMT_ICC_VERSION || FMT_NVCOMPILER_VERSION +# if FMT_HAS_BUILTIN(__builtin_ctz) || FMT_GCC_VERSION || FMT_ICC_VERSION || \ + FMT_NVCOMPILER_VERSION # define FMT_BUILTIN_CTZ(n) __builtin_ctz(n) # endif # if FMT_HAS_BUILTIN(__builtin_ctzll) || FMT_GCC_VERSION || \ @@ -2767,7 +2768,6 @@ FMT_FORMAT_AS(unsigned long, unsigned long long); FMT_FORMAT_AS(Char*, const Char*); FMT_FORMAT_AS(std::basic_string, basic_string_view); FMT_FORMAT_AS(std::nullptr_t, const void*); -FMT_FORMAT_AS(detail::byte, unsigned char); FMT_FORMAT_AS(detail::std_string_view, basic_string_view); template @@ -2875,6 +2875,11 @@ constexpr auto underlying(Enum e) noexcept -> return static_cast::type>(e); } +#ifdef __cpp_lib_byte +inline auto format_as(std::byte b) -> unsigned char { return underlying(b); } +FMT_FORMAT_AS(std::byte, unsigned char); +#endif + class bytes { private: string_view data_;