mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-22 10:30:05 +00:00
Add conditional_t for pre-C++14
This commit is contained in:
parent
4aa0dc578b
commit
c264e641ea
@ -450,9 +450,9 @@ struct chrono_formatter {
|
|||||||
OutputIt out;
|
OutputIt out;
|
||||||
int precision;
|
int precision;
|
||||||
// rep is unsigned to avoid overflow.
|
// rep is unsigned to avoid overflow.
|
||||||
using rep = typename std::conditional<
|
using rep =
|
||||||
std::is_integral<Rep>::value && sizeof(Rep) < sizeof(int), unsigned,
|
conditional_t<std::is_integral<Rep>::value && sizeof(Rep) < sizeof(int),
|
||||||
typename make_unsigned_or_unchanged<Rep>::type>::type;
|
unsigned, typename make_unsigned_or_unchanged<Rep>::type>;
|
||||||
rep val;
|
rep val;
|
||||||
typedef std::chrono::duration<rep> seconds;
|
typedef std::chrono::duration<rep> seconds;
|
||||||
seconds s;
|
seconds s;
|
||||||
|
@ -200,9 +200,11 @@
|
|||||||
|
|
||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
// An implementation of enable_if_t for pre-C++14 systems.
|
// Implementations of enable_if_t and other types for pre-C++14 systems.
|
||||||
template <bool B, class T = void>
|
template <bool B, class T = void>
|
||||||
using enable_if_t = typename std::enable_if<B, T>::type;
|
using enable_if_t = typename std::enable_if<B, T>::type;
|
||||||
|
template <bool B, class T, class F>
|
||||||
|
using conditional_t = typename std::conditional<B, T, F>::type;
|
||||||
|
|
||||||
// An enable_if helper to be used in template parameters which results in much
|
// An enable_if helper to be used in template parameters which results in much
|
||||||
// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
|
// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
|
||||||
@ -646,10 +648,9 @@ template <typename Char> struct string_value {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context> struct custom_value {
|
template <typename Context> struct custom_value {
|
||||||
|
using parse_context = basic_parse_context<typename Context::char_type>;
|
||||||
const void* value;
|
const void* value;
|
||||||
void (*format)(const void* arg,
|
void (*format)(const void* arg, parse_context& parse_ctx, Context& ctx);
|
||||||
basic_parse_context<typename Context::char_type>& parse_ctx,
|
|
||||||
Context& ctx);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename Context>
|
template <typename T, typename Context>
|
||||||
@ -704,10 +705,9 @@ template <typename Context> class value {
|
|||||||
// have different extension points, e.g. `formatter<T>` for `format` and
|
// have different extension points, e.g. `formatter<T>` for `format` and
|
||||||
// `printf_formatter<T>` for `printf`.
|
// `printf_formatter<T>` for `printf`.
|
||||||
custom.format = &format_custom_arg<
|
custom.format = &format_custom_arg<
|
||||||
T, typename std::conditional<
|
T, conditional_t<is_formattable<T, Context>::value,
|
||||||
is_formattable<T, Context>::value,
|
|
||||||
typename Context::template formatter_type<T>,
|
typename Context::template formatter_type<T>,
|
||||||
internal::fallback_formatter<T, char_type>>::type>;
|
internal::fallback_formatter<T, char_type>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const named_arg_base<char_type>& as_named_arg() {
|
const named_arg_base<char_type>& as_named_arg() {
|
||||||
@ -758,12 +758,11 @@ FMT_MAKE_VALUE_SAME(uint_type, unsigned)
|
|||||||
|
|
||||||
// To minimize the number of types we need to deal with, long is translated
|
// To minimize the number of types we need to deal with, long is translated
|
||||||
// either to int or to long long depending on its size.
|
// either to int or to long long depending on its size.
|
||||||
using long_type =
|
using long_type = conditional_t<sizeof(long) == sizeof(int), int, long long>;
|
||||||
std::conditional<sizeof(long) == sizeof(int), int, long long>::type;
|
|
||||||
FMT_MAKE_VALUE((sizeof(long) == sizeof(int) ? int_type : long_long_type), long,
|
FMT_MAKE_VALUE((sizeof(long) == sizeof(int) ? int_type : long_long_type), long,
|
||||||
long_type)
|
long_type)
|
||||||
using ulong_type = std::conditional<sizeof(unsigned long) == sizeof(unsigned),
|
using ulong_type = conditional_t<sizeof(unsigned long) == sizeof(unsigned),
|
||||||
unsigned, unsigned long long>::type;
|
unsigned, unsigned long long>;
|
||||||
FMT_MAKE_VALUE((sizeof(unsigned long) == sizeof(unsigned) ? uint_type
|
FMT_MAKE_VALUE((sizeof(unsigned long) == sizeof(unsigned) ? uint_type
|
||||||
: ulong_long_type),
|
: ulong_long_type),
|
||||||
unsigned long, ulong_type)
|
unsigned long, ulong_type)
|
||||||
@ -1129,9 +1128,8 @@ template <typename Context, typename... Args> class format_arg_store {
|
|||||||
// Packed is a macro on MinGW so use IS_PACKED instead.
|
// Packed is a macro on MinGW so use IS_PACKED instead.
|
||||||
static const bool IS_PACKED = NUM_ARGS < internal::max_packed_args;
|
static const bool IS_PACKED = NUM_ARGS < internal::max_packed_args;
|
||||||
|
|
||||||
using value_type =
|
using value_type = conditional_t<IS_PACKED, internal::value<Context>,
|
||||||
typename std::conditional<IS_PACKED, internal::value<Context>,
|
basic_format_arg<Context>>;
|
||||||
basic_format_arg<Context>>::type;
|
|
||||||
|
|
||||||
// If the arguments are not packed, add one more element to mark the end.
|
// If the arguments are not packed, add one more element to mark the end.
|
||||||
static const size_t DATA_SIZE =
|
static const size_t DATA_SIZE =
|
||||||
@ -1274,7 +1272,7 @@ template <typename Context> class basic_format_args {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** An alias to ``basic_format_args<context>``. */
|
/** An alias to ``basic_format_args<context>``. */
|
||||||
// It is a separate type rather than a typedef to make symbols readable.
|
// It is a separate type rather than an alias to make symbols readable.
|
||||||
struct format_args : basic_format_args<format_context> {
|
struct format_args : basic_format_args<format_context> {
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
format_args(Args&&... arg)
|
format_args(Args&&... arg)
|
||||||
|
@ -698,8 +698,8 @@ FMT_CONSTEXPR bool is_negative(T) {
|
|||||||
template <typename T> struct int_traits {
|
template <typename T> struct int_traits {
|
||||||
// Smallest of uint32_t and uint64_t that is large enough to represent
|
// Smallest of uint32_t and uint64_t that is large enough to represent
|
||||||
// all values of T.
|
// all values of T.
|
||||||
typedef typename std::conditional<std::numeric_limits<T>::digits <= 32,
|
using main_type =
|
||||||
uint32_t, uint64_t>::type main_type;
|
conditional_t<std::numeric_limits<T>::digits <= 32, uint32_t, uint64_t>;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Static data is placed in this class template to allow header-only
|
// Static data is placed in this class template to allow header-only
|
||||||
@ -2181,9 +2181,10 @@ FMT_CONSTEXPR const typename ParseContext::char_type* parse_format_specs(
|
|||||||
ParseContext& ctx) {
|
ParseContext& ctx) {
|
||||||
// GCC 7.2 requires initializer.
|
// GCC 7.2 requires initializer.
|
||||||
typedef typename ParseContext::char_type char_type;
|
typedef typename ParseContext::char_type char_type;
|
||||||
typename std::conditional<is_formattable<T, format_context>::value,
|
conditional_t<is_formattable<T, format_context>::value,
|
||||||
formatter<T, char_type>,
|
formatter<T, char_type>,
|
||||||
internal::fallback_formatter<T, char_type>>::type f;
|
internal::fallback_formatter<T, char_type>>
|
||||||
|
f;
|
||||||
return f.parse(ctx);
|
return f.parse(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,9 +440,8 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
|
|||||||
typedef format_part<char_type> value_type;
|
typedef format_part<char_type> value_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef typename std::conditional<static_cast<bool>(number_of_format_parts),
|
using type = conditional_t<static_cast<bool>(number_of_format_parts),
|
||||||
format_parts_array<number_of_format_parts>,
|
format_parts_array<number_of_format_parts>, empty>;
|
||||||
empty>::type type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Parts> class compiletime_prepared_parts_collector {
|
template <typename Parts> class compiletime_prepared_parts_collector {
|
||||||
@ -674,9 +673,8 @@ struct compiletime_format_tag {};
|
|||||||
struct runtime_format_tag {};
|
struct runtime_format_tag {};
|
||||||
|
|
||||||
template <typename Format> struct format_tag {
|
template <typename Format> struct format_tag {
|
||||||
typedef typename std::conditional<is_compile_string<Format>::value,
|
using type = conditional_t<is_compile_string<Format>::value,
|
||||||
compiletime_format_tag,
|
compiletime_format_tag, runtime_format_tag>;
|
||||||
runtime_format_tag>::type type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if FMT_USE_CONSTEXPR
|
#if FMT_USE_CONSTEXPR
|
||||||
|
@ -91,15 +91,14 @@ class arg_converter : public function<void> {
|
|||||||
template <typename U, FMT_ENABLE_IF(std::is_integral<U>::value)>
|
template <typename U, FMT_ENABLE_IF(std::is_integral<U>::value)>
|
||||||
void operator()(U value) {
|
void operator()(U value) {
|
||||||
bool is_signed = type_ == 'd' || type_ == 'i';
|
bool is_signed = type_ == 'd' || type_ == 'i';
|
||||||
typedef typename std::conditional<std::is_same<T, void>::value, U, T>::type
|
using target_type = conditional_t<std::is_same<T, void>::value, U, T>;
|
||||||
TargetType;
|
if (const_check(sizeof(target_type) <= sizeof(int))) {
|
||||||
if (const_check(sizeof(TargetType) <= sizeof(int))) {
|
|
||||||
// Extra casts are used to silence warnings.
|
// Extra casts are used to silence warnings.
|
||||||
if (is_signed) {
|
if (is_signed) {
|
||||||
arg_ = internal::make_arg<Context>(
|
arg_ = internal::make_arg<Context>(
|
||||||
static_cast<int>(static_cast<TargetType>(value)));
|
static_cast<int>(static_cast<target_type>(value)));
|
||||||
} else {
|
} else {
|
||||||
typedef typename make_unsigned_or_bool<TargetType>::type Unsigned;
|
typedef typename make_unsigned_or_bool<target_type>::type Unsigned;
|
||||||
arg_ = internal::make_arg<Context>(
|
arg_ = internal::make_arg<Context>(
|
||||||
static_cast<unsigned>(static_cast<Unsigned>(value)));
|
static_cast<unsigned>(static_cast<Unsigned>(value)));
|
||||||
}
|
}
|
||||||
|
@ -94,11 +94,11 @@ template <typename T, typename _ = void> struct is_range_ : std::false_type {};
|
|||||||
|
|
||||||
#if !FMT_MSC_VER || FMT_MSC_VER > 1800
|
#if !FMT_MSC_VER || FMT_MSC_VER > 1800
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_range_<T, typename std::conditional<
|
struct is_range_<
|
||||||
false,
|
T, conditional_t<false,
|
||||||
conditional_helper<decltype(std::declval<T>().begin()),
|
conditional_helper<decltype(std::declval<T>().begin()),
|
||||||
decltype(std::declval<T>().end())>,
|
decltype(std::declval<T>().end())>,
|
||||||
void>::type> : std::true_type {};
|
void>> : std::true_type {};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// tuple_size and tuple_element check.
|
/// tuple_size and tuple_element check.
|
||||||
|
Loading…
Reference in New Issue
Block a user