Move std::byte formatter to std.h

This commit is contained in:
Victor Zverovich
2026-02-03 06:52:46 -08:00
parent b98926b73b
commit eb99f6eba6
7 changed files with 27 additions and 35 deletions

View File

@@ -9,6 +9,8 @@
#define FMT_FORMAT_INL_H_
#ifndef FMT_MODULE
# include <stddef.h> // ptrdiff_t
# include <algorithm>
# include <cerrno> // errno
# include <climits>

View File

@@ -51,9 +51,8 @@
# include <stdlib.h> // malloc, free
# include <string.h> // memcpy
# include <cmath> // std::signbit
# include <cstddef> // std::byte
# include <limits> // std::numeric_limits
# include <cmath> // std::signbit
# include <limits> // std::numeric_limits
# if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI)
// Workaround for pre gcc 5 libstdc++.
# include <memory> // std::allocator_traits
@@ -4069,19 +4068,6 @@ constexpr auto format_as(Enum e) noexcept -> underlying_t<Enum> {
}
} // namespace enums
#ifdef __cpp_lib_byte
template <typename Char>
struct formatter<std::byte, Char> : formatter<unsigned, Char> {
static auto format_as(std::byte b) -> unsigned char {
return static_cast<unsigned char>(b);
}
template <typename Context>
auto format(std::byte b, Context& ctx) const -> decltype(ctx.out()) {
return formatter<unsigned, Char>::format(format_as(b), ctx);
}
};
#endif
struct bytes {
string_view data;

View File

@@ -15,7 +15,8 @@
# include <atomic>
# include <bitset>
# include <complex>
# include <exception>
# include <cstddef> // std::byte
# include <exception> // std::exception
# include <functional> // std::reference_wrapper
# include <memory>
# include <thread>
@@ -666,6 +667,19 @@ struct formatter<BitRef, Char,
}
};
#ifdef __cpp_lib_byte
template <typename Char>
struct formatter<std::byte, Char> : formatter<unsigned, Char> {
static auto format_as(std::byte b) -> unsigned char {
return static_cast<unsigned char>(b);
}
template <typename Context>
auto format(std::byte b, Context& ctx) const -> decltype(ctx.out()) {
return formatter<unsigned, Char>::format(format_as(b), ctx);
}
};
#endif
template <typename T, typename Char>
struct formatter<std::atomic<T>, Char,
enable_if_t<is_formattable<T, Char>::value>>