mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-27 12:39:56 +00:00
Simplify byte handling
This commit is contained in:
parent
c7173a36a1
commit
35c0286cd8
@ -8,7 +8,6 @@
|
||||
#ifndef FMT_CORE_H_
|
||||
#define FMT_CORE_H_
|
||||
|
||||
#include <cstddef> // std::byte
|
||||
#include <cstdio> // std::FILE
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
@ -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 <typename Char> using std_string_view = std::basic_string_view<Char>;
|
||||
#elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW)
|
||||
@ -1429,10 +1422,6 @@ template <typename Context> struct arg_mapper {
|
||||
return map(format_as(val));
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR FMT_INLINE auto map(detail::byte val) -> unsigned {
|
||||
return map(static_cast<unsigned char>(val));
|
||||
}
|
||||
|
||||
template <typename T, typename U = remove_cvref_t<T>>
|
||||
struct formattable
|
||||
: bool_constant<has_const_formatter<U, Context>() ||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#define FMT_FORMAT_H_
|
||||
|
||||
#include <cmath> // std::signbit
|
||||
#include <cstddef> // std::byte
|
||||
#include <cstdint> // uint32_t
|
||||
#include <cstring> // std::memcpy
|
||||
#include <limits> // 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<Char>, basic_string_view<Char>);
|
||||
FMT_FORMAT_AS(std::nullptr_t, const void*);
|
||||
FMT_FORMAT_AS(detail::byte, unsigned char);
|
||||
FMT_FORMAT_AS(detail::std_string_view<Char>, basic_string_view<Char>);
|
||||
|
||||
template <typename Char>
|
||||
@ -2875,6 +2875,11 @@ constexpr auto underlying(Enum e) noexcept ->
|
||||
return static_cast<typename std::underlying_type<Enum>::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_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user