Move _BitInt to format.h

This commit is contained in:
Victor Zverovich
2026-01-29 21:54:47 -08:00
parent 26c6b1c23d
commit 71c63792dd
2 changed files with 38 additions and 33 deletions
+38 -2
View File
@@ -198,6 +198,23 @@ struct is_contiguous<std::basic_string<Char, Traits, Allocator>>
namespace detail {
#ifdef FMT_USE_BITINT
// Use the provided definition.
#elif FMT_CLANG_VERSION >= 1500 && !defined(__CUDACC__)
# define FMT_USE_BITINT 1
#else
# define FMT_USE_BITINT 0
#endif
#if FMT_USE_BITINT
FMT_PRAGMA_CLANG(diagnostic ignored "-Wbit-int-extension")
template <int N> using bitint = _BitInt(N);
template <int N> using ubitint = unsigned _BitInt(N);
#else
template <int N> struct bitint {};
template <int N> struct ubitint {};
#endif // FMT_USE_BITINT
// __builtin_clz is broken in clang with Microsoft codegen:
// https://github.com/fmtlib/fmt/issues/519.
#if !FMT_MSC_VERSION
@@ -4039,9 +4056,28 @@ class formatter<std::basic_string<Char, Traits, Allocator>, Char>
: public formatter<basic_string_view<Char>, Char> {};
template <int N, typename Char>
struct formatter<detail::bitint<N>, Char> : formatter<long long, Char> {};
struct formatter<detail::bitint<N>, Char> : formatter<long long, Char> {
static_assert(N <= 64, "unsupported _BitInt");
static auto format_as(detail::bitint<N> x) -> long long {
return static_cast<long long>(x);
}
template <typename Context>
auto format(detail::bitint<N> x, Context& ctx) const -> decltype(ctx.out()) {
return formatter<long long, Char>::format(format_as(x), ctx);
}
};
template <int N, typename Char>
struct formatter<detail::ubitint<N>, Char> : formatter<ullong, Char> {};
struct formatter<detail::ubitint<N>, Char> : formatter<ullong, Char> {
static_assert(N <= 64, "unsupported _BitInt");
static auto format_as(detail::ubitint<N> x) -> ullong {
return static_cast<ullong>(x);
}
template <typename Context>
auto format(detail::ubitint<N> x, Context& ctx) const -> decltype(ctx.out()) {
return formatter<ullong, Char>::format(format_as(x), ctx);
}
};
template <typename Char>
struct formatter<detail::float128, Char>