Remove old is_constructible workarounds and replace typedefs with using

This commit is contained in:
Victor Zverovich 2019-06-02 16:04:17 -07:00
parent 4d4b8c238d
commit ec6651087d
3 changed files with 56 additions and 85 deletions

View File

@ -204,6 +204,10 @@ FMT_BEGIN_NAMESPACE
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;
// An enable_if helper to be used in template parameters which results in much
// shorter symbols: https://godbolt.org/z/sWw4vP.
#define FMT_ENABLE_IF(...) enable_if_t<__VA_ARGS__, int> = 0
namespace internal { namespace internal {
#if defined(FMT_USE_STRING_VIEW) #if defined(FMT_USE_STRING_VIEW)
@ -215,10 +219,6 @@ using std_string_view = std::experimental::basic_string_view<Char>;
template <typename T> struct std_string_view {}; template <typename T> struct std_string_view {};
#endif #endif
// An enable_if helper to be used in template parameters which results in much
// shorter symbols: https://godbolt.org/z/sWw4vP.
#define FMT_ENABLE_IF(...) enable_if_t<__VA_ARGS__, int> = 0
#if (__cplusplus >= 201703L || \ #if (__cplusplus >= 201703L || \
(defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) && \ (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) && \
__cpp_lib_is_invocable >= 201703L __cpp_lib_is_invocable >= 201703L
@ -266,8 +266,8 @@ template <typename T> class buffer {
virtual void grow(std::size_t capacity) = 0; virtual void grow(std::size_t capacity) = 0;
public: public:
typedef T value_type; using value_type = T;
typedef const T& const_reference; using const_reference = const T&;
virtual ~buffer() {} virtual ~buffer() {}
@ -334,7 +334,7 @@ class container_buffer : public buffer<typename Container::value_type> {
// Extracts a reference to the container from back_insert_iterator. // Extracts a reference to the container from back_insert_iterator.
template <typename Container> template <typename Container>
inline Container& get_container(std::back_insert_iterator<Container> it) { inline Container& get_container(std::back_insert_iterator<Container> it) {
typedef std::back_insert_iterator<Container> bi_iterator; using bi_iterator = std::back_insert_iterator<Container>;
struct accessor : bi_iterator { struct accessor : bi_iterator {
accessor(bi_iterator iter) : bi_iterator(iter) {} accessor(bi_iterator iter) : bi_iterator(iter) {}
using bi_iterator::container; using bi_iterator::container;
@ -349,23 +349,6 @@ struct error_handler {
// This function is intentionally not constexpr to give a compile-time error. // This function is intentionally not constexpr to give a compile-time error.
FMT_API FMT_NORETURN void on_error(const char* message); FMT_API FMT_NORETURN void on_error(const char* message);
}; };
// GCC 4.6.x cannot expand `T...`.
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 407
typedef char yes[1];
typedef char no[2];
template <typename T, typename V> struct is_constructible {
template <typename U>
static yes& test(int (*)[sizeof(new U(std::declval<V>()))]);
template <typename U> static no& test(...);
enum { value = sizeof(test<T>(nullptr)) == sizeof(yes) };
};
#else
template <typename... T>
struct is_constructible : std::is_constructible<T...> {};
#endif
struct dummy_formatter_arg {}; // Workaround broken is_constructible in MSVC.
} // namespace internal } // namespace internal
/** /**
@ -381,8 +364,8 @@ template <typename Char> class basic_string_view {
size_t size_; size_t size_;
public: public:
typedef Char char_type; using char_type = Char;
typedef const Char* iterator; using iterator = const Char*;
FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {} FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {}
@ -455,8 +438,8 @@ template <typename Char> class basic_string_view {
} }
}; };
typedef basic_string_view<char> string_view; using string_view = basic_string_view<char>;
typedef basic_string_view<wchar_t> wstring_view; using wstring_view = basic_string_view<wchar_t>;
/** /**
\rst \rst
@ -525,8 +508,8 @@ class basic_parse_context : private ErrorHandler {
int next_arg_id_; int next_arg_id_;
public: public:
typedef Char char_type; using char_type = Char;
typedef typename basic_string_view<Char>::iterator iterator; using iterator = typename basic_string_view<Char>::iterator;
explicit FMT_CONSTEXPR basic_parse_context(basic_string_view<Char> format_str, explicit FMT_CONSTEXPR basic_parse_context(basic_string_view<Char> format_str,
ErrorHandler eh = ErrorHandler()) ErrorHandler eh = ErrorHandler())
@ -567,11 +550,11 @@ class basic_parse_context : private ErrorHandler {
FMT_CONSTEXPR ErrorHandler error_handler() const { return *this; } FMT_CONSTEXPR ErrorHandler error_handler() const { return *this; }
}; };
typedef basic_parse_context<char> format_parse_context; using format_parse_context = basic_parse_context<char>;
typedef basic_parse_context<wchar_t> wformat_parse_context; using wformat_parse_context = basic_parse_context<wchar_t>;
FMT_DEPRECATED typedef basic_parse_context<char> parse_context; using parse_context FMT_DEPRECATED = basic_parse_context<char>;
FMT_DEPRECATED typedef basic_parse_context<wchar_t> wparse_context; using wparse_context FMT_DEPRECATED = basic_parse_context<wchar_t>;
template <typename Context> class basic_format_arg; template <typename Context> class basic_format_arg;
template <typename Context> class basic_format_args; template <typename Context> class basic_format_args;
@ -579,7 +562,7 @@ template <typename Context> class basic_format_args;
// A formatter for objects of type T. // A formatter for objects of type T.
template <typename T, typename Char = char, typename Enable = void> template <typename T, typename Char = char, typename Enable = void>
struct formatter { struct formatter {
explicit formatter(internal::dummy_formatter_arg); formatter() = delete;
}; };
template <typename T, typename Char, typename Enable = void> template <typename T, typename Char, typename Enable = void>
@ -669,18 +652,14 @@ template <typename Context> struct custom_value {
Context& ctx); Context& ctx);
}; };
template <typename T, typename Context> struct is_formattable { template <typename T, typename Context>
enum { using is_formattable =
value = std::is_constructible<typename Context::template formatter_type<T>>;
!is_constructible<typename Context::template formatter_type<T>::type,
internal::dummy_formatter_arg>::value
};
};
// A formatting argument value. // A formatting argument value.
template <typename Context> class value { template <typename Context> class value {
public: public:
typedef typename Context::char_type char_type; using char_type = typename Context::char_type;
union { union {
int int_value; int int_value;
@ -727,7 +706,7 @@ template <typename Context> class value {
custom.format = &format_custom_arg< custom.format = &format_custom_arg<
T, typename std::conditional< T, typename std::conditional<
is_formattable<T, Context>::value, is_formattable<T, Context>::value,
typename Context::template formatter_type<T>::type, typename Context::template formatter_type<T>,
internal::fallback_formatter<T, char_type>>::type>; internal::fallback_formatter<T, char_type>>::type>;
} }
@ -779,12 +758,12 @@ 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.
typedef std::conditional<sizeof(long) == sizeof(int), int, long long>::type using long_type =
long_type; 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)
typedef std::conditional<sizeof(unsigned long) == sizeof(unsigned), unsigned, using ulong_type = std::conditional<sizeof(unsigned long) == sizeof(unsigned),
unsigned long long>::type ulong_type; unsigned, unsigned long long>::type;
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)
@ -849,8 +828,9 @@ inline init<C, int, int_type> make_value(const T& val) {
return static_cast<int>(val); return static_cast<int>(val);
} }
template <typename C, typename T, typename Char = typename C::char_type, template <
FMT_ENABLE_IF(is_constructible<basic_string_view<Char>, T>::value && typename C, typename T, typename Char = typename C::char_type,
FMT_ENABLE_IF(std::is_constructible<basic_string_view<Char>, T>::value &&
!internal::is_string<T>::value)> !internal::is_string<T>::value)>
inline init<C, basic_string_view<Char>, string_type> make_value(const T& val) { inline init<C, basic_string_view<Char>, string_type> make_value(const T& val) {
return basic_string_view<Char>(val); return basic_string_view<Char>(val);
@ -864,7 +844,7 @@ template <
FMT_ENABLE_IF(!convert_to_int<U, Char>::value && FMT_ENABLE_IF(!convert_to_int<U, Char>::value &&
!std::is_same<U, Char>::value && !std::is_same<U, Char>::value &&
!std::is_convertible<U, basic_string_view<Char>>::value && !std::is_convertible<U, basic_string_view<Char>>::value &&
!is_constructible<basic_string_view<Char>, U>::value && !std::is_constructible<basic_string_view<Char>, U>::value &&
!internal::is_string<U>::value)> !internal::is_string<U>::value)>
inline init<C, const T&, custom_type> make_value(const T& val) { inline init<C, const T&, custom_type> make_value(const T& val) {
return val; return val;
@ -913,7 +893,7 @@ template <typename Context> class basic_format_arg {
friend class basic_format_args<Context>; friend class basic_format_args<Context>;
friend class internal::arg_map<Context>; friend class internal::arg_map<Context>;
typedef typename Context::char_type char_type; using char_type = typename Context::char_type;
public: public:
class handle { class handle {
@ -952,7 +932,7 @@ struct monostate {};
template <typename Visitor, typename Context> template <typename Visitor, typename Context>
FMT_CONSTEXPR internal::invoke_result_t<Visitor, int> visit_format_arg( FMT_CONSTEXPR internal::invoke_result_t<Visitor, int> visit_format_arg(
Visitor&& vis, const basic_format_arg<Context>& arg) { Visitor&& vis, const basic_format_arg<Context>& arg) {
typedef typename Context::char_type char_type; using char_type = typename Context::char_type;
switch (arg.type_) { switch (arg.type_) {
case internal::none_type: case internal::none_type:
break; break;
@ -1001,7 +981,7 @@ template <typename Context> class arg_map {
arg_map(const arg_map&) = delete; arg_map(const arg_map&) = delete;
void operator=(const arg_map&) = delete; void operator=(const arg_map&) = delete;
typedef typename Context::char_type char_type; using char_type = typename Context::char_type;
struct entry { struct entry {
basic_string_view<char_type> name; basic_string_view<char_type> name;
@ -1084,7 +1064,7 @@ inline basic_format_arg<Context> make_arg(const T& value) {
template <typename OutputIt, typename Char> class basic_format_context { template <typename OutputIt, typename Char> class basic_format_context {
public: public:
/** The character type for the output. */ /** The character type for the output. */
typedef Char char_type; using char_type = Char;
private: private:
OutputIt out_; OutputIt out_;
@ -1096,13 +1076,9 @@ template <typename OutputIt, typename Char> class basic_format_context {
void operator=(const basic_format_context&) = delete; void operator=(const basic_format_context&) = delete;
public: public:
typedef OutputIt iterator; using iterator = OutputIt;
typedef basic_format_arg<basic_format_context> format_arg; using format_arg = basic_format_arg<basic_format_context> ;
template <typename T> using formatter_type = formatter<T, char_type>;
// using formatter_type = formatter<T, char_type>;
template <typename T> struct formatter_type {
typedef formatter<T, char_type> type;
};
/** /**
Constructs a ``basic_format_context`` object. References to the arguments are Constructs a ``basic_format_context`` object. References to the arguments are
@ -1137,8 +1113,8 @@ template <typename Char> struct buffer_context {
std::back_insert_iterator<internal::buffer<Char>>, Char> std::back_insert_iterator<internal::buffer<Char>>, Char>
type; type;
}; };
typedef buffer_context<char>::type format_context; using format_context = buffer_context<char>::type;
typedef buffer_context<wchar_t>::type wformat_context; using wformat_context = buffer_context<wchar_t>::type;
/** /**
\rst \rst
@ -1154,8 +1130,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;
typedef typename std::conditional<IS_PACKED, internal::value<Context>, using value_type = typename std::conditional<IS_PACKED, internal::value<Context>,
basic_format_arg<Context>>::type value_type; 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 =
@ -1213,8 +1189,8 @@ inline format_arg_store<Context, Args...> make_format_args(
/** Formatting arguments. */ /** Formatting arguments. */
template <typename Context> class basic_format_args { template <typename Context> class basic_format_args {
public: public:
typedef unsigned size_type; using size_type = unsigned;
typedef basic_format_arg<Context> format_arg; using format_arg = basic_format_arg<Context>;
private: private:
// To reduce compiled code size per formatting function call, types of first // To reduce compiled code size per formatting function call, types of first

View File

@ -329,12 +329,9 @@ template <typename T> struct printf_formatter {
template <typename OutputIt, typename Char> class basic_printf_context { template <typename OutputIt, typename Char> class basic_printf_context {
public: public:
/** The character type for the output. */ /** The character type for the output. */
typedef Char char_type; using char_type = Char;
typedef basic_format_arg<basic_printf_context> format_arg; using format_arg = basic_format_arg<basic_printf_context>;
template <typename T> using formatter_type = printf_formatter<T>;
template <typename T> struct formatter_type {
typedef printf_formatter<T> type;
};
private: private:
typedef basic_format_specs<char_type> format_specs; typedef basic_format_specs<char_type> format_specs;

View File

@ -209,7 +209,6 @@ struct custom_context {
typedef char char_type; typedef char char_type;
template <typename T> struct formatter_type { template <typename T> struct formatter_type {
struct type {
template <typename ParseContext> template <typename ParseContext>
auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
return ctx.begin(); return ctx.begin();
@ -220,7 +219,6 @@ struct custom_context {
return nullptr; return nullptr;
} }
}; };
};
bool called; bool called;
fmt::format_parse_context ctx; fmt::format_parse_context ctx;