mirror of
https://github.com/fmtlib/fmt.git
synced 2026-02-05 17:30:06 +08:00
Add an alias for unsigned long long
This commit is contained in:
parent
ed409c5ba9
commit
9237a45439
@ -320,6 +320,8 @@ using underlying_t = typename std::underlying_type<T>::type;
|
||||
template <typename T> using decay_t = typename std::decay<T>::type;
|
||||
using nullptr_t = decltype(nullptr);
|
||||
|
||||
using ullong = unsigned long long;
|
||||
|
||||
#if (FMT_GCC_VERSION && FMT_GCC_VERSION < 500) || FMT_MSC_VERSION
|
||||
// A workaround for gcc 4.9 & MSVC v141 to make void_t work in a SFINAE context.
|
||||
template <typename...> struct void_t_impl {
|
||||
@ -1014,7 +1016,7 @@ struct type_constant : std::integral_constant<type, type::custom_type> {};
|
||||
FMT_TYPE_CONSTANT(int, int_type);
|
||||
FMT_TYPE_CONSTANT(unsigned, uint_type);
|
||||
FMT_TYPE_CONSTANT(long long, long_long_type);
|
||||
FMT_TYPE_CONSTANT(unsigned long long, ulong_long_type);
|
||||
FMT_TYPE_CONSTANT(ullong, ulong_long_type);
|
||||
FMT_TYPE_CONSTANT(int128_opt, int128_type);
|
||||
FMT_TYPE_CONSTANT(uint128_opt, uint128_type);
|
||||
FMT_TYPE_CONSTANT(bool, bool_type);
|
||||
@ -1131,7 +1133,7 @@ FMT_CONSTEXPR void init_static_named_arg(named_arg_info<Char>* named_args,
|
||||
// either to int or to long long depending on its size.
|
||||
enum { long_short = sizeof(long) == sizeof(int) && FMT_BUILTIN_TYPES };
|
||||
using long_type = conditional_t<long_short, int, long long>;
|
||||
using ulong_type = conditional_t<long_short, unsigned, unsigned long long>;
|
||||
using ulong_type = conditional_t<long_short, unsigned, ullong>;
|
||||
|
||||
template <typename T>
|
||||
using format_as_result =
|
||||
@ -1185,7 +1187,7 @@ template <typename Char> struct type_mapper {
|
||||
static auto map(long) -> long_type;
|
||||
static auto map(unsigned long) -> ulong_type;
|
||||
static auto map(long long) -> long long;
|
||||
static auto map(unsigned long long) -> unsigned long long;
|
||||
static auto map(ullong) -> ullong;
|
||||
static auto map(int128_opt) -> int128_opt;
|
||||
static auto map(uint128_opt) -> uint128_opt;
|
||||
static auto map(bool) -> bool;
|
||||
@ -1193,8 +1195,7 @@ template <typename Char> struct type_mapper {
|
||||
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, unsigned long long, void>;
|
||||
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<
|
||||
@ -2178,7 +2179,7 @@ template <typename Context> class value {
|
||||
int int_value;
|
||||
unsigned uint_value;
|
||||
long long long_long_value;
|
||||
unsigned long long ulong_long_value;
|
||||
ullong ulong_long_value;
|
||||
int128_opt int128_value;
|
||||
uint128_opt uint128_value;
|
||||
bool bool_value;
|
||||
@ -2203,8 +2204,7 @@ template <typename Context> class value {
|
||||
constexpr FMT_INLINE value(unsigned long x FMT_BUILTIN)
|
||||
: value(ulong_type(x)) {}
|
||||
constexpr FMT_INLINE value(long long x FMT_BUILTIN) : long_long_value(x) {}
|
||||
constexpr FMT_INLINE value(unsigned long long x FMT_BUILTIN)
|
||||
: ulong_long_value(x) {}
|
||||
constexpr FMT_INLINE value(ullong x FMT_BUILTIN) : ulong_long_value(x) {}
|
||||
FMT_INLINE value(int128_opt x FMT_BUILTIN) : int128_value(x) {}
|
||||
FMT_INLINE value(uint128_opt x FMT_BUILTIN) : uint128_value(x) {}
|
||||
constexpr FMT_INLINE value(bool x FMT_BUILTIN) : bool_value(x) {}
|
||||
@ -2324,8 +2324,8 @@ template <typename Context> class value {
|
||||
enum { packed_arg_bits = 4 };
|
||||
// Maximum number of arguments with packed types.
|
||||
enum { max_packed_args = 62 / packed_arg_bits };
|
||||
enum : unsigned long long { is_unpacked_bit = 1ULL << 63 };
|
||||
enum : unsigned long long { has_named_args_bit = 1ULL << 62 };
|
||||
enum : ullong { is_unpacked_bit = 1ULL << 63 };
|
||||
enum : ullong { has_named_args_bit = 1ULL << 62 };
|
||||
|
||||
template <typename It, typename T, typename Enable = void>
|
||||
struct is_output_iterator : std::false_type {};
|
||||
@ -2338,18 +2338,16 @@ struct is_output_iterator<
|
||||
enable_if_t<std::is_assignable<decltype(*std::declval<decay_t<It>&>()++),
|
||||
T>::value>> : std::true_type {};
|
||||
|
||||
template <typename> constexpr auto encode_types() -> unsigned long long {
|
||||
return 0;
|
||||
}
|
||||
template <typename> constexpr auto encode_types() -> ullong { return 0; }
|
||||
|
||||
template <typename Context, typename First, typename... T>
|
||||
constexpr auto encode_types() -> unsigned long long {
|
||||
constexpr auto encode_types() -> ullong {
|
||||
return static_cast<unsigned>(stored_type_constant<First, Context>::value) |
|
||||
(encode_types<Context, T...>() << packed_arg_bits);
|
||||
}
|
||||
|
||||
template <typename Context, typename... T, size_t NUM_ARGS = sizeof...(T)>
|
||||
constexpr auto make_descriptor() -> unsigned long long {
|
||||
constexpr auto make_descriptor() -> ullong {
|
||||
return NUM_ARGS <= max_packed_args ? encode_types<Context, T...>()
|
||||
: is_unpacked_bit | NUM_ARGS;
|
||||
}
|
||||
@ -2358,8 +2356,7 @@ template <typename Context, int NUM_ARGS>
|
||||
using arg_t = conditional_t<NUM_ARGS <= max_packed_args, value<Context>,
|
||||
basic_format_arg<Context>>;
|
||||
|
||||
template <typename Context, int NUM_ARGS, int NUM_NAMED_ARGS,
|
||||
unsigned long long DESC>
|
||||
template <typename Context, int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC>
|
||||
struct named_arg_store {
|
||||
// args_[0].named_args points to named_args to avoid bloating format_args.
|
||||
arg_t<Context, NUM_ARGS> args[1u + NUM_ARGS];
|
||||
@ -2391,8 +2388,7 @@ struct named_arg_store {
|
||||
// An array of references to arguments. It can be implicitly converted to
|
||||
// `basic_format_args` for passing into type-erased formatting functions
|
||||
// such as `vformat`. It is a plain struct to reduce binary size in debug mode.
|
||||
template <typename Context, int NUM_ARGS, int NUM_NAMED_ARGS,
|
||||
unsigned long long DESC>
|
||||
template <typename Context, int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC>
|
||||
struct format_arg_store {
|
||||
// +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
|
||||
using type =
|
||||
@ -2585,7 +2581,7 @@ template <typename Context> class basic_format_args {
|
||||
// If the number of arguments is less or equal to max_packed_args then
|
||||
// argument types are passed in the descriptor. This reduces binary code size
|
||||
// per formatting function call.
|
||||
unsigned long long desc_;
|
||||
ullong desc_;
|
||||
union {
|
||||
// If is_packed() returns true then argument values are stored in values_;
|
||||
// otherwise they are stored in args_. This is done to improve cache
|
||||
@ -2609,7 +2605,7 @@ template <typename Context> class basic_format_args {
|
||||
return static_cast<detail::type>((desc_ >> shift) & mask);
|
||||
}
|
||||
|
||||
template <int NUM_ARGS, int NUM_NAMED_ARGS, unsigned long long DESC>
|
||||
template <int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC>
|
||||
using store =
|
||||
detail::format_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC>;
|
||||
|
||||
@ -2619,14 +2615,14 @@ template <typename Context> class basic_format_args {
|
||||
constexpr basic_format_args() : desc_(0), args_(nullptr) {}
|
||||
|
||||
/// Constructs a `basic_format_args` object from `format_arg_store`.
|
||||
template <int NUM_ARGS, int NUM_NAMED_ARGS, unsigned long long DESC,
|
||||
template <int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC,
|
||||
FMT_ENABLE_IF(NUM_ARGS <= detail::max_packed_args)>
|
||||
constexpr FMT_ALWAYS_INLINE basic_format_args(
|
||||
const store<NUM_ARGS, NUM_NAMED_ARGS, DESC>& s)
|
||||
: desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)),
|
||||
values_(s.args) {}
|
||||
|
||||
template <int NUM_ARGS, int NUM_NAMED_ARGS, unsigned long long DESC,
|
||||
template <int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC,
|
||||
FMT_ENABLE_IF(NUM_ARGS > detail::max_packed_args)>
|
||||
constexpr basic_format_args(const store<NUM_ARGS, NUM_NAMED_ARGS, DESC>& s)
|
||||
: desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)),
|
||||
@ -2670,8 +2666,7 @@ template <typename Context> class basic_format_args {
|
||||
}
|
||||
|
||||
auto max_size() const -> int {
|
||||
unsigned long long max_packed = detail::max_packed_args;
|
||||
return static_cast<int>(is_packed() ? max_packed
|
||||
return static_cast<int>(is_packed() ? ullong(detail::max_packed_args)
|
||||
: desc_ & ~detail::is_unpacked_bit);
|
||||
}
|
||||
};
|
||||
@ -2816,7 +2811,7 @@ struct formatter<T, Char,
|
||||
template <typename Context = context, typename... T,
|
||||
int NUM_ARGS = sizeof...(T),
|
||||
int NUM_NAMED_ARGS = detail::count_named_args<T...>(),
|
||||
unsigned long long DESC = detail::make_descriptor<Context, T...>()>
|
||||
ullong DESC = detail::make_descriptor<Context, T...>()>
|
||||
constexpr FMT_ALWAYS_INLINE auto make_format_args(T&... args)
|
||||
-> detail::format_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC> {
|
||||
// Suppress warnings for pathological types convertible to detail::value.
|
||||
|
||||
@ -544,8 +544,7 @@ namespace detail {
|
||||
// https://johnnylee-sde.github.io/Fast-unsigned-integer-to-time-string/.
|
||||
inline void write_digit2_separated(char* buf, unsigned a, unsigned b,
|
||||
unsigned c, char sep) {
|
||||
unsigned long long digits =
|
||||
a | (b << 24) | (static_cast<unsigned long long>(c) << 48);
|
||||
ullong digits = a | (b << 24) | (static_cast<ullong>(c) << 48);
|
||||
// Convert each value to BCD.
|
||||
// We have x = a * 10 + b and we want to convert it to BCD y = a * 16 + b.
|
||||
// The difference is
|
||||
@ -559,7 +558,7 @@ inline void write_digit2_separated(char* buf, unsigned a, unsigned b,
|
||||
// Put low nibbles to high bytes and high nibbles to low bytes.
|
||||
digits = ((digits & 0x00f00000f00000f0) >> 4) |
|
||||
((digits & 0x000f00000f00000f) << 8);
|
||||
auto usep = static_cast<unsigned long long>(sep);
|
||||
auto usep = static_cast<ullong>(sep);
|
||||
// Add ASCII '0' to each digit byte and insert separators.
|
||||
digits |= 0x3030003030003030 | (usep << 16) | (usep << 40);
|
||||
|
||||
|
||||
@ -394,11 +394,11 @@ class uint128_fallback {
|
||||
return *this;
|
||||
}
|
||||
#if FMT_HAS_BUILTIN(__builtin_addcll) && !defined(__ibmxl__)
|
||||
unsigned long long carry;
|
||||
ullong carry;
|
||||
lo_ = __builtin_addcll(lo_, n, 0, &carry);
|
||||
hi_ += carry;
|
||||
#elif FMT_HAS_BUILTIN(__builtin_ia32_addcarryx_u64) && !defined(__ibmxl__)
|
||||
unsigned long long result;
|
||||
ullong result;
|
||||
auto carry = __builtin_ia32_addcarryx_u64(0, lo_, n, &result);
|
||||
lo_ = result;
|
||||
hi_ += carry;
|
||||
@ -1645,7 +1645,7 @@ template <typename F> struct basic_fp {
|
||||
}
|
||||
};
|
||||
|
||||
using fp = basic_fp<unsigned long long>;
|
||||
using fp = basic_fp<ullong>;
|
||||
|
||||
// Normalizes the value converted from double and multiplied by (1 << SHIFT).
|
||||
template <int SHIFT = 0, typename F>
|
||||
@ -3733,12 +3733,12 @@ template <typename Char> struct arg_formatter {
|
||||
|
||||
struct dynamic_spec_getter {
|
||||
template <typename T, FMT_ENABLE_IF(is_integer<T>::value)>
|
||||
FMT_CONSTEXPR auto operator()(T value) -> unsigned long long {
|
||||
return is_negative(value) ? ~0ull : static_cast<unsigned long long>(value);
|
||||
FMT_CONSTEXPR auto operator()(T value) -> ullong {
|
||||
return is_negative(value) ? ~0ull : static_cast<ullong>(value);
|
||||
}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(!is_integer<T>::value)>
|
||||
FMT_CONSTEXPR auto operator()(T) -> unsigned long long {
|
||||
FMT_CONSTEXPR auto operator()(T) -> ullong {
|
||||
report_error("width/precision is not integer");
|
||||
return 0;
|
||||
}
|
||||
@ -3752,7 +3752,7 @@ FMT_CONSTEXPR void handle_dynamic_spec(
|
||||
auto arg =
|
||||
kind == arg_id_kind::index ? ctx.arg(ref.index) : ctx.arg(ref.name);
|
||||
if (!arg) report_error("argument not found");
|
||||
unsigned long long result = arg.visit(dynamic_spec_getter());
|
||||
ullong result = arg.visit(dynamic_spec_getter());
|
||||
if (result > to_unsigned(max_value<int>()))
|
||||
report_error("width/precision is out of range");
|
||||
value = static_cast<int>(result);
|
||||
@ -3982,8 +3982,7 @@ class formatter<std::basic_string<Char, Traits, Allocator>, Char>
|
||||
template <int N, typename Char>
|
||||
struct formatter<detail::bitint<N>, Char> : formatter<long long, Char> {};
|
||||
template <int N, typename Char>
|
||||
struct formatter<detail::ubitint<N>, Char>
|
||||
: formatter<unsigned long long, Char> {};
|
||||
struct formatter<detail::ubitint<N>, Char> : formatter<ullong, Char> {};
|
||||
|
||||
template <typename Char>
|
||||
struct formatter<detail::float128, Char>
|
||||
@ -4210,7 +4209,7 @@ class format_int {
|
||||
private:
|
||||
// Buffer should be large enough to hold all digits (digits10 + 1),
|
||||
// a sign and a null character.
|
||||
enum { buffer_size = std::numeric_limits<unsigned long long>::digits10 + 3 };
|
||||
enum { buffer_size = std::numeric_limits<ullong>::digits10 + 3 };
|
||||
mutable char buffer_[buffer_size];
|
||||
char* str_;
|
||||
|
||||
@ -4240,7 +4239,7 @@ class format_int {
|
||||
: str_(format_unsigned(value)) {}
|
||||
FMT_CONSTEXPR20 explicit format_int(unsigned long value)
|
||||
: str_(format_unsigned(value)) {}
|
||||
FMT_CONSTEXPR20 explicit format_int(unsigned long long value)
|
||||
FMT_CONSTEXPR20 explicit format_int(ullong value)
|
||||
: str_(format_unsigned(value)) {}
|
||||
|
||||
/// Returns the number of characters written to the output buffer.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user