mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-08 12:20:06 +00:00
Cleanup
This commit is contained in:
parent
3ada4aed20
commit
3e9fdb3a1f
@ -143,21 +143,6 @@
|
||||
# define FMT_CONSTEXPR20
|
||||
#endif
|
||||
|
||||
#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS)
|
||||
// Use the provided definition.
|
||||
#elif defined(__NVCOMPILER)
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
|
||||
#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
|
||||
#elif defined(__cpp_nontype_template_args) && \
|
||||
__cpp_nontype_template_args >= 201911L
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
|
||||
#elif FMT_CLANG_VERSION >= 1200 && FMT_CPLUSPLUS >= 202002L
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
|
||||
#else
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
|
||||
#endif
|
||||
|
||||
// Check if exceptions are disabled.
|
||||
#ifdef FMT_EXCEPTIONS
|
||||
// Use the provided definition.
|
||||
@ -176,17 +161,6 @@
|
||||
# define FMT_CATCH(x) if (false)
|
||||
#endif
|
||||
|
||||
// Check if RTTI is disabled.
|
||||
#ifdef FMT_USE_RTTI
|
||||
// Use the provided definition.
|
||||
#elif defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \
|
||||
defined(__INTEL_RTTI__) || defined(__RTTI)
|
||||
// __RTTI is for EDG compilers. _CPPRTTI is for MSVC.
|
||||
# define FMT_USE_RTTI 1
|
||||
#else
|
||||
# define FMT_USE_RTTI 0
|
||||
#endif
|
||||
|
||||
#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough)
|
||||
# define FMT_FALLTHROUGH [[fallthrough]]
|
||||
#elif defined(__clang__)
|
||||
@ -1564,7 +1538,6 @@ FMT_CONSTEXPR auto parse_format_specs(const Char* begin, const Char* end,
|
||||
++begin;
|
||||
break;
|
||||
case '+':
|
||||
FMT_FALLTHROUGH;
|
||||
case ' ':
|
||||
specs.set_sign(c == ' ' ? sign::space : sign::plus);
|
||||
FMT_FALLTHROUGH;
|
||||
@ -2228,50 +2201,38 @@ template <typename Context> class value {
|
||||
};
|
||||
|
||||
constexpr FMT_INLINE value() : no_value() {}
|
||||
constexpr FMT_INLINE value(int val) : int_value(val) {}
|
||||
constexpr FMT_INLINE value(unsigned val FMT_BUILTIN) : uint_value(val) {}
|
||||
FMT_CONSTEXPR FMT_INLINE value(long val FMT_BUILTIN) {
|
||||
if (sizeof(long) == sizeof(int))
|
||||
int_value = static_cast<int>(val);
|
||||
else
|
||||
long_long_value = val;
|
||||
}
|
||||
FMT_CONSTEXPR FMT_INLINE value(unsigned long val FMT_BUILTIN) {
|
||||
if (sizeof(long) == sizeof(int))
|
||||
uint_value = static_cast<unsigned>(val);
|
||||
else
|
||||
ulong_long_value = val;
|
||||
}
|
||||
constexpr FMT_INLINE value(long long val FMT_BUILTIN)
|
||||
: long_long_value(val) {}
|
||||
constexpr FMT_INLINE value(unsigned long long val FMT_BUILTIN)
|
||||
: ulong_long_value(val) {}
|
||||
constexpr FMT_INLINE value(int x) : int_value(x) {}
|
||||
constexpr FMT_INLINE value(unsigned x FMT_BUILTIN) : uint_value(x) {}
|
||||
FMT_CONSTEXPR FMT_INLINE value(long x FMT_BUILTIN) : value(long_type(x)) {}
|
||||
FMT_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) {}
|
||||
template <int N>
|
||||
constexpr FMT_INLINE value(bitint<N> val FMT_BUILTIN)
|
||||
: long_long_value(val) {}
|
||||
constexpr FMT_INLINE value(bitint<N> x FMT_BUILTIN) : long_long_value(x) {}
|
||||
template <int N>
|
||||
constexpr FMT_INLINE value(ubitint<N> val FMT_BUILTIN)
|
||||
: ulong_long_value(val) {}
|
||||
FMT_INLINE value(int128_opt val FMT_BUILTIN) : int128_value(val) {}
|
||||
FMT_INLINE value(uint128_opt val FMT_BUILTIN) : uint128_value(val) {}
|
||||
constexpr FMT_INLINE value(float val FMT_BUILTIN) : float_value(val) {}
|
||||
constexpr FMT_INLINE value(double val FMT_BUILTIN) : double_value(val) {}
|
||||
FMT_INLINE value(long double val FMT_BUILTIN) : long_double_value(val) {}
|
||||
constexpr FMT_INLINE value(bool val FMT_BUILTIN) : bool_value(val) {}
|
||||
constexpr FMT_INLINE value(ubitint<N> 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(float x FMT_BUILTIN) : float_value(x) {}
|
||||
constexpr FMT_INLINE value(double x FMT_BUILTIN) : double_value(x) {}
|
||||
FMT_INLINE value(long double x FMT_BUILTIN) : long_double_value(x) {}
|
||||
constexpr FMT_INLINE value(bool x FMT_BUILTIN) : bool_value(x) {}
|
||||
template <typename T, FMT_ENABLE_IF(is_char<T>::value)>
|
||||
constexpr FMT_INLINE value(T val FMT_BUILTIN) : char_value(val) {
|
||||
constexpr FMT_INLINE value(T x FMT_BUILTIN) : char_value(x) {
|
||||
static_assert(std::is_same<T, char_type>::value,
|
||||
"mixing character types is disallowed");
|
||||
}
|
||||
FMT_CONSTEXPR FMT_INLINE value(const char_type* val FMT_BUILTIN) {
|
||||
string.data = val;
|
||||
FMT_CONSTEXPR FMT_INLINE value(const char_type* x FMT_BUILTIN) {
|
||||
string.data = x;
|
||||
if (is_constant_evaluated()) string.size = {};
|
||||
}
|
||||
FMT_CONSTEXPR FMT_INLINE value(basic_string_view<char_type> val FMT_BUILTIN) {
|
||||
string.data = val.data();
|
||||
string.size = val.size();
|
||||
FMT_CONSTEXPR FMT_INLINE value(basic_string_view<char_type> x FMT_BUILTIN) {
|
||||
string.data = x.data();
|
||||
string.size = x.size();
|
||||
}
|
||||
FMT_INLINE value(const void* val FMT_BUILTIN) : pointer(val) {}
|
||||
FMT_INLINE value(const void* x FMT_BUILTIN) : pointer(x) {}
|
||||
|
||||
// We can't use mapped_t because of a bug in MSVC 2017.
|
||||
template <
|
||||
@ -2279,8 +2240,8 @@ template <typename Context> class value {
|
||||
typename M = decltype(arg_mapper<char_type>::map(std::declval<T&>())),
|
||||
FMT_ENABLE_IF(!std::is_same<T, M>::value &&
|
||||
!std::is_integral<remove_cvref_t<T>>::value)>
|
||||
FMT_CONSTEXPR20 FMT_INLINE value(T&& val) {
|
||||
*this = arg_mapper<char_type>::map(val);
|
||||
FMT_CONSTEXPR20 FMT_INLINE value(T&& x) {
|
||||
*this = arg_mapper<char_type>::map(x);
|
||||
}
|
||||
|
||||
template <
|
||||
@ -2288,7 +2249,7 @@ template <typename Context> class value {
|
||||
typename M = decltype(arg_mapper<char_type>::map(std::declval<T&>())),
|
||||
FMT_ENABLE_IF(std::is_same<T, M>::value &&
|
||||
!std::is_integral<remove_cvref_t<T>>::value)>
|
||||
FMT_CONSTEXPR20 FMT_INLINE value(T&& val) {
|
||||
FMT_CONSTEXPR20 FMT_INLINE value(T&& x) {
|
||||
// Use enum instead of constexpr because the latter may generate code.
|
||||
enum { formattable_char = !std::is_same<T, unformattable_char>::value };
|
||||
static_assert(formattable_char, "mixing character types is disallowed");
|
||||
@ -2309,13 +2270,13 @@ template <typename Context> class value {
|
||||
if constexpr (!formattable) type_is_unformattable_for<T, char_type> _;
|
||||
|
||||
if constexpr (std::is_same<T, int>::value) {
|
||||
int_value = val; // int is always handled as a built-in type.
|
||||
int_value = x; // int is always handled as a built-in type.
|
||||
return;
|
||||
}
|
||||
|
||||
// T may overload operator& e.g. std::vector<bool>::reference in libc++.
|
||||
if constexpr (std::is_same<decltype(&val), remove_reference_t<T>*>::value)
|
||||
custom.value = const_cast<value_type*>(&val);
|
||||
if constexpr (std::is_same<decltype(&x), remove_reference_t<T>*>::value)
|
||||
custom.value = const_cast<value_type*>(&x);
|
||||
#endif
|
||||
|
||||
static_assert(
|
||||
@ -2325,7 +2286,7 @@ template <typename Context> class value {
|
||||
|
||||
if (!is_constant_evaluated())
|
||||
custom.value =
|
||||
const_cast<char*>(&reinterpret_cast<const volatile char&>(val));
|
||||
const_cast<char*>(&reinterpret_cast<const volatile char&>(x));
|
||||
// Get the formatter type through the context to allow different contexts
|
||||
// have different extension points, e.g. `formatter<T>` for `format` and
|
||||
// `printf_formatter<T>` for `printf`.
|
||||
@ -2415,9 +2376,7 @@ template <typename Context, size_t NUM_ARGS, size_t NUM_NAMED_ARGS,
|
||||
struct named_arg_store {
|
||||
// args_[0].named_args points to named_args to avoid bloating format_args.
|
||||
// +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
|
||||
static constexpr size_t ARGS_ARRAY_SIZE = 1 + (NUM_ARGS != 0 ? NUM_ARGS : +1);
|
||||
|
||||
arg_t<Context, NUM_ARGS> args[ARGS_ARRAY_SIZE];
|
||||
arg_t<Context, NUM_ARGS> args[1 + (NUM_ARGS != 0 ? NUM_ARGS : +1)];
|
||||
named_arg_info<typename Context::char_type> named_args[NUM_NAMED_ARGS];
|
||||
|
||||
template <typename... T>
|
||||
@ -2430,7 +2389,8 @@ struct named_arg_store {
|
||||
|
||||
named_arg_store(named_arg_store&& rhs) {
|
||||
args[0] = {named_args, NUM_NAMED_ARGS};
|
||||
for (size_t i = 1; i < ARGS_ARRAY_SIZE; ++i) args[i] = rhs.args[i];
|
||||
for (size_t i = 1; i < sizeof(args) / sizeof(*args); ++i)
|
||||
args[i] = rhs.args[i];
|
||||
for (size_t i = 0; i < NUM_NAMED_ARGS; ++i)
|
||||
named_args[i] = rhs.named_args[i];
|
||||
}
|
||||
@ -2438,6 +2398,7 @@ struct named_arg_store {
|
||||
named_arg_store(const named_arg_store& rhs) = delete;
|
||||
named_arg_store& operator=(const named_arg_store& rhs) = delete;
|
||||
named_arg_store& operator=(named_arg_store&& rhs) = delete;
|
||||
operator const arg_t<Context, NUM_ARGS>*() const { return args + 1; }
|
||||
};
|
||||
|
||||
// An array of references to arguments. It can be implicitly converted to
|
||||
@ -2694,35 +2655,23 @@ template <typename Context> class basic_format_args {
|
||||
|
||||
/// Constructs a `basic_format_args` object from `format_arg_store`.
|
||||
template <size_t NUM_ARGS, size_t NUM_NAMED_ARGS, unsigned long long DESC,
|
||||
FMT_ENABLE_IF(NUM_ARGS <= detail::max_packed_args &&
|
||||
NUM_NAMED_ARGS == 0)>
|
||||
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), values_(s.args) {}
|
||||
: desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)),
|
||||
values_(s.args) {}
|
||||
|
||||
template <size_t NUM_ARGS, size_t NUM_NAMED_ARGS, unsigned long long DESC,
|
||||
FMT_ENABLE_IF(NUM_ARGS <= detail::max_packed_args &&
|
||||
NUM_NAMED_ARGS != 0)>
|
||||
FMT_ENABLE_IF(NUM_ARGS > detail::max_packed_args)>
|
||||
constexpr basic_format_args(const store<NUM_ARGS, NUM_NAMED_ARGS, DESC>& s)
|
||||
: desc_(DESC | detail::has_named_args_bit), values_(s.args.args + 1) {}
|
||||
|
||||
template <size_t NUM_ARGS, size_t NUM_NAMED_ARGS, unsigned long long DESC,
|
||||
FMT_ENABLE_IF(NUM_ARGS > detail::max_packed_args &&
|
||||
NUM_NAMED_ARGS == 0)>
|
||||
constexpr basic_format_args(const store<NUM_ARGS, NUM_NAMED_ARGS, DESC>& s)
|
||||
: desc_(DESC), args_(s.args) {}
|
||||
|
||||
template <size_t NUM_ARGS, size_t NUM_NAMED_ARGS, unsigned long long DESC,
|
||||
FMT_ENABLE_IF(NUM_ARGS > detail::max_packed_args &&
|
||||
NUM_NAMED_ARGS != 0)>
|
||||
constexpr basic_format_args(const store<NUM_ARGS, NUM_NAMED_ARGS, DESC>& s)
|
||||
: desc_(DESC | detail::has_named_args_bit), args_(s.args.args + 1) {}
|
||||
: desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)),
|
||||
args_(s.args) {}
|
||||
|
||||
/// Constructs a `basic_format_args` object from a dynamic list of arguments.
|
||||
constexpr basic_format_args(const format_arg* args, int count,
|
||||
bool has_named = false)
|
||||
: desc_(detail::is_unpacked_bit | detail::to_unsigned(count) |
|
||||
(has_named ? +detail::has_named_args_bit : 0ULL)),
|
||||
(has_named ? +detail::has_named_args_bit : 0)),
|
||||
args_(args) {}
|
||||
|
||||
/// Returns the argument with the specified id.
|
||||
@ -2880,7 +2829,6 @@ using is_formattable = bool_constant<
|
||||
detail::mapped_t<conditional_t<std::is_void<T>::value,
|
||||
detail::unformattable, T>,
|
||||
Char>>::value>;
|
||||
|
||||
#ifdef __cpp_concepts
|
||||
template <typename T, typename Char = char>
|
||||
concept formattable = is_formattable<remove_reference_t<T>, Char>::value;
|
||||
|
@ -68,12 +68,38 @@
|
||||
# endif
|
||||
#endif // FMT_MODULE
|
||||
|
||||
#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS)
|
||||
// Use the provided definition.
|
||||
#elif defined(__NVCOMPILER)
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
|
||||
#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
|
||||
#elif defined(__cpp_nontype_template_args) && \
|
||||
__cpp_nontype_template_args >= 201911L
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
|
||||
#elif FMT_CLANG_VERSION >= 1200 && FMT_CPLUSPLUS >= 202002L
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
|
||||
#else
|
||||
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
|
||||
#endif
|
||||
|
||||
#if defined __cpp_inline_variables && __cpp_inline_variables >= 201606L
|
||||
# define FMT_INLINE_VARIABLE inline
|
||||
#else
|
||||
# define FMT_INLINE_VARIABLE
|
||||
#endif
|
||||
|
||||
// Check if RTTI is disabled.
|
||||
#ifdef FMT_USE_RTTI
|
||||
// Use the provided definition.
|
||||
#elif defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \
|
||||
defined(__INTEL_RTTI__) || defined(__RTTI)
|
||||
// __RTTI is for EDG compilers. _CPPRTTI is for MSVC.
|
||||
# define FMT_USE_RTTI 1
|
||||
#else
|
||||
# define FMT_USE_RTTI 0
|
||||
#endif
|
||||
|
||||
// Visibility when compiled as a shared library/object.
|
||||
#if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
|
||||
# define FMT_SO_VISIBILITY(value) FMT_VISIBILITY(value)
|
||||
|
Loading…
Reference in New Issue
Block a user