Skip to content

Commit 71c6379

Browse files
committed
Move _BitInt to format.h
1 parent 26c6b1c commit 71c6379

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

include/fmt/base.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -409,23 +409,6 @@ inline auto map(int128_opt) -> monostate { return {}; }
409409
inline auto map(uint128_opt) -> monostate { return {}; }
410410
#endif
411411

412-
#ifdef FMT_USE_BITINT
413-
// Use the provided definition.
414-
#elif FMT_CLANG_VERSION >= 1500 && !defined(__CUDACC__)
415-
# define FMT_USE_BITINT 1
416-
#else
417-
# define FMT_USE_BITINT 0
418-
#endif
419-
420-
#if FMT_USE_BITINT
421-
FMT_PRAGMA_CLANG(diagnostic ignored "-Wbit-int-extension")
422-
template <int N> using bitint = _BitInt(N);
423-
template <int N> using ubitint = unsigned _BitInt(N);
424-
#else
425-
template <int N> struct bitint {};
426-
template <int N> struct ubitint {};
427-
#endif // FMT_USE_BITINT
428-
429412
// Casts a nonnegative integer to unsigned.
430413
template <typename Int>
431414
FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t<Int> {
@@ -1177,11 +1160,6 @@ template <typename Char> struct type_mapper {
11771160
static auto map(uint128_opt) -> uint128_opt;
11781161
static auto map(bool) -> bool;
11791162

1180-
template <int N>
1181-
static auto map(bitint<N>) -> conditional_t<N <= 64, long long, void>;
1182-
template <int N>
1183-
static auto map(ubitint<N>) -> conditional_t<N <= 64, ullong, void>;
1184-
11851163
template <typename T, FMT_ENABLE_IF(is_code_unit<T>::value)>
11861164
static auto map(T) -> conditional_t<
11871165
std::is_same<T, char>::value || std::is_same<T, Char>::value, Char, void>;
@@ -2130,15 +2108,6 @@ template <typename Context> class value {
21302108
FMT_INLINE value(uint128_opt x FMT_BUILTIN) : uint128_value(x) {}
21312109
constexpr FMT_INLINE value(bool x FMT_BUILTIN) : bool_value(x) {}
21322110

2133-
template <int N>
2134-
constexpr FMT_INLINE value(bitint<N> x FMT_BUILTIN) : long_long_value(x) {
2135-
static_assert(N <= 64, "unsupported _BitInt");
2136-
}
2137-
template <int N>
2138-
constexpr FMT_INLINE value(ubitint<N> x FMT_BUILTIN) : ulong_long_value(x) {
2139-
static_assert(N <= 64, "unsupported _BitInt");
2140-
}
2141-
21422111
template <typename T, FMT_ENABLE_IF(is_code_unit<T>::value)>
21432112
constexpr FMT_INLINE value(T x FMT_BUILTIN) : char_value(x) {
21442113
static_assert(

include/fmt/format.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,23 @@ struct is_contiguous<std::basic_string<Char, Traits, Allocator>>
198198

199199
namespace detail {
200200

201+
#ifdef FMT_USE_BITINT
202+
// Use the provided definition.
203+
#elif FMT_CLANG_VERSION >= 1500 && !defined(__CUDACC__)
204+
# define FMT_USE_BITINT 1
205+
#else
206+
# define FMT_USE_BITINT 0
207+
#endif
208+
209+
#if FMT_USE_BITINT
210+
FMT_PRAGMA_CLANG(diagnostic ignored "-Wbit-int-extension")
211+
template <int N> using bitint = _BitInt(N);
212+
template <int N> using ubitint = unsigned _BitInt(N);
213+
#else
214+
template <int N> struct bitint {};
215+
template <int N> struct ubitint {};
216+
#endif // FMT_USE_BITINT
217+
201218
// __builtin_clz is broken in clang with Microsoft codegen:
202219
// https://github.com/fmtlib/fmt/issues/519.
203220
#if !FMT_MSC_VERSION
@@ -4039,9 +4056,28 @@ class formatter<std::basic_string<Char, Traits, Allocator>, Char>
40394056
: public formatter<basic_string_view<Char>, Char> {};
40404057

40414058
template <int N, typename Char>
4042-
struct formatter<detail::bitint<N>, Char> : formatter<long long, Char> {};
4059+
struct formatter<detail::bitint<N>, Char> : formatter<long long, Char> {
4060+
static_assert(N <= 64, "unsupported _BitInt");
4061+
static auto format_as(detail::bitint<N> x) -> long long {
4062+
return static_cast<long long>(x);
4063+
}
4064+
template <typename Context>
4065+
auto format(detail::bitint<N> x, Context& ctx) const -> decltype(ctx.out()) {
4066+
return formatter<long long, Char>::format(format_as(x), ctx);
4067+
}
4068+
};
4069+
40434070
template <int N, typename Char>
4044-
struct formatter<detail::ubitint<N>, Char> : formatter<ullong, Char> {};
4071+
struct formatter<detail::ubitint<N>, Char> : formatter<ullong, Char> {
4072+
static_assert(N <= 64, "unsupported _BitInt");
4073+
static auto format_as(detail::ubitint<N> x) -> ullong {
4074+
return static_cast<ullong>(x);
4075+
}
4076+
template <typename Context>
4077+
auto format(detail::ubitint<N> x, Context& ctx) const -> decltype(ctx.out()) {
4078+
return formatter<ullong, Char>::format(format_as(x), ctx);
4079+
}
4080+
};
40454081

40464082
template <typename Char>
40474083
struct formatter<detail::float128, Char>

0 commit comments

Comments
 (0)