Repository: fmtlib/fmt
File: include/fmt/base.h (C/C++)

Code before:
    !(FMT_CLANG_VERSION && FMT_MSC_VERSION)
#  define FMT_USE_INT128 1
using int128_opt = __int128_t;  // An optional native 128-bit integer.
using uint128_opt = __uint128_t;
template <typename T> inline auto convert_for_visit(T value) -> T {
  return value;
}
#else
#  define FMT_USE_INT128 0
#endif
#if !FMT_USE_INT128
enum class int128_opt {};
enum class uint128_opt {};
// Reduce template instantiations.
template <typename T> auto convert_for_visit(T) -> monostate { return {}; }
#endif

#ifndef FMT_USE_BITINT
#  if FMT_CLANG_VERSION >= 1400
#    define FMT_USE_BITINT 1
#  else
#    define FMT_USE_BITINT 0
#  endif
#endif

template <class T, int N = 0> struct bitint_traits : std::false_type {};
#if FMT_USE_BITINT
#  pragma clang diagnostic push
#  pragma clang diagnostic ignored "-Wbit-int-extension"

// fmt only supports up to 128 bits https://github.com/fmtlib/fmt/pull/4072
template <int N> struct bitint_traits<_BitInt(N)> : std::true_type {
  static constexpr bool is_signed = true;
  static constexpr size_t number_of_bits = N;
  static constexpr bool is_formattable = number_of_bits <= 128;
};
template <int N> struct bitint_traits<unsigned _BitInt(N)> : std::true_type {
  static constexpr bool is_signed = false;
  static constexpr size_t number_of_bits = N;
  static constexpr bool is_formattable = number_of_bits <= 128;
};

#endif

// Casts a nonnegative integer to unsigned.
template <typename Int>
FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t<Int> {
  FMT_ASSERT(std::is_unsigned<Int>::value || value >= 0, "negative value");
  return static_cast<make_unsigned_t<Int>>(value);
}


Review comment (suggestion):
I don't think this should inherit from `false_type`. Instead you might need to add `is_formattable = false` to disable overloads for types other than `_BitInt`.

Code after:
#elif defined(__SIZEOF_INT128__) && !defined(__NVCC__) && \
    !(FMT_CLANG_VERSION && FMT_MSC_VERSION)
#  define FMT_USE_INT128 1
using int128_opt = __int128_t;  // An optional native 128-bit integer.
using uint128_opt = __uint128_t;
template <typename T> inline auto convert_for_visit(T value) -> T {
  return value;
}
#else
#  define FMT_USE_INT128 0
#endif
#if !FMT_USE_INT128
enum class int128_opt {};
enum class uint128_opt {};
// Reduce template instantiations.
template <typename T> auto convert_for_visit(T) -> monostate { return {}; }
#endif

#ifndef FMT_USE_BITINT
#  if FMT_CLANG_VERSION >= 1400
#    define FMT_USE_BITINT 1
#  else
#    define FMT_USE_BITINT 0
#  endif
#endif

template <class T, int N = 0> struct bitint_traits {};
#if FMT_USE_BITINT
#  pragma clang diagnostic push
#  pragma clang diagnostic ignored "-Wbit-int-extension"

// fmt only supports up to 128 bits https://github.com/fmtlib/fmt/pull/4072
template <int N> struct bitint_traits<_BitInt(N)> {
  static constexpr bool is_formattable = N <= 128;
  using formatter_type = conditional_t<(N <= 64), long long, __int128>;
};
template <int N> struct bitint_traits<unsigned _BitInt(N)> {
  static constexpr bool is_formattable = N <= 128;
  using formatter_type =
      conditional_t<(N <= 64), unsigned long long, unsigned __int128>;
};

#  pragma clang diagnostic pop
#endif

// Casts a nonnegative integer to unsigned.
template <typename Int>
FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t<Int> {
  FMT_ASSERT(std::is_unsigned<Int>::value || value >= 0, "negative value");
  return static_cast<make_unsigned_t<Int>>(value);
}