mirror of
https://github.com/fmtlib/fmt.git
synced 2026-02-06 01:39:55 +08:00
Move _BitInt to format.h
This commit is contained in:
parent
26c6b1c23d
commit
71c63792dd
@ -409,23 +409,6 @@ inline auto map(int128_opt) -> monostate { return {}; }
|
||||
inline auto map(uint128_opt) -> monostate { return {}; }
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
// Casts a nonnegative integer to unsigned.
|
||||
template <typename Int>
|
||||
FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t<Int> {
|
||||
@ -1177,11 +1160,6 @@ template <typename Char> struct type_mapper {
|
||||
static auto map(uint128_opt) -> uint128_opt;
|
||||
static auto map(bool) -> bool;
|
||||
|
||||
template <int N>
|
||||
static auto map(bitint<N>) -> conditional_t<N <= 64, long long, void>;
|
||||
template <int N>
|
||||
static auto map(ubitint<N>) -> conditional_t<N <= 64, ullong, void>;
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(is_code_unit<T>::value)>
|
||||
static auto map(T) -> conditional_t<
|
||||
std::is_same<T, char>::value || std::is_same<T, Char>::value, Char, void>;
|
||||
@ -2130,15 +2108,6 @@ template <typename Context> class value {
|
||||
FMT_INLINE value(uint128_opt x FMT_BUILTIN) : uint128_value(x) {}
|
||||
constexpr FMT_INLINE value(bool x FMT_BUILTIN) : bool_value(x) {}
|
||||
|
||||
template <int N>
|
||||
constexpr FMT_INLINE value(bitint<N> x FMT_BUILTIN) : long_long_value(x) {
|
||||
static_assert(N <= 64, "unsupported _BitInt");
|
||||
}
|
||||
template <int N>
|
||||
constexpr FMT_INLINE value(ubitint<N> x FMT_BUILTIN) : ulong_long_value(x) {
|
||||
static_assert(N <= 64, "unsupported _BitInt");
|
||||
}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(is_code_unit<T>::value)>
|
||||
constexpr FMT_INLINE value(T x FMT_BUILTIN) : char_value(x) {
|
||||
static_assert(
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user