From c264e641eafcbec43b8bff4feea57428f1c38bb4 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 4 Jun 2019 18:50:30 -0700 Subject: [PATCH] Add conditional_t for pre-C++14 --- include/fmt/chrono.h | 6 +++--- include/fmt/core.h | 30 ++++++++++++++---------------- include/fmt/format.h | 11 ++++++----- include/fmt/prepare.h | 10 ++++------ include/fmt/printf.h | 9 ++++----- include/fmt/ranges.h | 10 +++++----- 6 files changed, 36 insertions(+), 40 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 738f1beadd59..46efc511440b 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -450,9 +450,9 @@ struct chrono_formatter { OutputIt out; int precision; // rep is unsigned to avoid overflow. - using rep = typename std::conditional< - std::is_integral::value && sizeof(Rep) < sizeof(int), unsigned, - typename make_unsigned_or_unchanged::type>::type; + using rep = + conditional_t::value && sizeof(Rep) < sizeof(int), + unsigned, typename make_unsigned_or_unchanged::type>; rep val; typedef std::chrono::duration seconds; seconds s; diff --git a/include/fmt/core.h b/include/fmt/core.h index b684d6152a8e..c339d0b028b8 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -200,9 +200,11 @@ 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 using enable_if_t = typename std::enable_if::type; +template +using conditional_t = typename std::conditional::type; // 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 @@ -646,10 +648,9 @@ template struct string_value { }; template struct custom_value { + using parse_context = basic_parse_context; const void* value; - void (*format)(const void* arg, - basic_parse_context& parse_ctx, - Context& ctx); + void (*format)(const void* arg, parse_context& parse_ctx, Context& ctx); }; template @@ -704,10 +705,9 @@ template class value { // have different extension points, e.g. `formatter` for `format` and // `printf_formatter` for `printf`. custom.format = &format_custom_arg< - T, typename std::conditional< - is_formattable::value, - typename Context::template formatter_type, - internal::fallback_formatter>::type>; + T, conditional_t::value, + typename Context::template formatter_type, + internal::fallback_formatter>>; } const named_arg_base& 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 // either to int or to long long depending on its size. -using long_type = - std::conditional::type; +using long_type = conditional_t; FMT_MAKE_VALUE((sizeof(long) == sizeof(int) ? int_type : long_long_type), long, long_type) -using ulong_type = std::conditional::type; +using ulong_type = conditional_t; FMT_MAKE_VALUE((sizeof(unsigned long) == sizeof(unsigned) ? uint_type : ulong_long_type), unsigned long, ulong_type) @@ -1129,9 +1128,8 @@ template class format_arg_store { // Packed is a macro on MinGW so use IS_PACKED instead. static const bool IS_PACKED = NUM_ARGS < internal::max_packed_args; - using value_type = - typename std::conditional, - basic_format_arg>::type; + using value_type = conditional_t, + basic_format_arg>; // If the arguments are not packed, add one more element to mark the end. static const size_t DATA_SIZE = @@ -1274,7 +1272,7 @@ template class basic_format_args { }; /** An alias to ``basic_format_args``. */ -// 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 { template format_args(Args&&... arg) diff --git a/include/fmt/format.h b/include/fmt/format.h index 1507b4ea9541..fa0a473aac3e 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -698,8 +698,8 @@ FMT_CONSTEXPR bool is_negative(T) { template struct int_traits { // Smallest of uint32_t and uint64_t that is large enough to represent // all values of T. - typedef typename std::conditional::digits <= 32, - uint32_t, uint64_t>::type main_type; + using main_type = + conditional_t::digits <= 32, uint32_t, uint64_t>; }; // 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) { // GCC 7.2 requires initializer. typedef typename ParseContext::char_type char_type; - typename std::conditional::value, - formatter, - internal::fallback_formatter>::type f; + conditional_t::value, + formatter, + internal::fallback_formatter> + f; return f.parse(ctx); } diff --git a/include/fmt/prepare.h b/include/fmt/prepare.h index 9b30b5d6b760..a7078ef80294 100644 --- a/include/fmt/prepare.h +++ b/include/fmt/prepare.h @@ -440,9 +440,8 @@ template class compiletime_prepared_parts_type_provider { typedef format_part value_type; }; - typedef typename std::conditional(number_of_format_parts), - format_parts_array, - empty>::type type; + using type = conditional_t(number_of_format_parts), + format_parts_array, empty>; }; template class compiletime_prepared_parts_collector { @@ -674,9 +673,8 @@ struct compiletime_format_tag {}; struct runtime_format_tag {}; template struct format_tag { - typedef typename std::conditional::value, - compiletime_format_tag, - runtime_format_tag>::type type; + using type = conditional_t::value, + compiletime_format_tag, runtime_format_tag>; }; #if FMT_USE_CONSTEXPR diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 29f36323a55c..0828c321f21b 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -91,15 +91,14 @@ class arg_converter : public function { template ::value)> void operator()(U value) { bool is_signed = type_ == 'd' || type_ == 'i'; - typedef typename std::conditional::value, U, T>::type - TargetType; - if (const_check(sizeof(TargetType) <= sizeof(int))) { + using target_type = conditional_t::value, U, T>; + if (const_check(sizeof(target_type) <= sizeof(int))) { // Extra casts are used to silence warnings. if (is_signed) { arg_ = internal::make_arg( - static_cast(static_cast(value))); + static_cast(static_cast(value))); } else { - typedef typename make_unsigned_or_bool::type Unsigned; + typedef typename make_unsigned_or_bool::type Unsigned; arg_ = internal::make_arg( static_cast(static_cast(value))); } diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index a3a0c7a03c88..18124d3a4fa0 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -94,11 +94,11 @@ template struct is_range_ : std::false_type {}; #if !FMT_MSC_VER || FMT_MSC_VER > 1800 template -struct is_range_().begin()), - decltype(std::declval().end())>, - void>::type> : std::true_type {}; +struct is_range_< + T, conditional_t().begin()), + decltype(std::declval().end())>, + void>> : std::true_type {}; #endif /// tuple_size and tuple_element check.