diff --git a/fmt/format.h b/fmt/format.h index be884d76..fee63d08 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -1142,57 +1142,55 @@ template struct is_named_arg : std::false_type {}; template -struct is_named_arg< named_arg > : std::true_type {}; +struct is_named_arg> : std::true_type {}; template -constexpr Type gettype() { - return is_named_arg::value ? - NAMED_ARG : (convert_to_int::value ? INT : CUSTOM); +constexpr Type get_type() { + return std::is_reference::value || std::is_array::value ? + get_type::type>() : + (is_named_arg::value ? + NAMED_ARG : (convert_to_int::value ? INT : CUSTOM)); } -template <> constexpr Type gettype() { return BOOL; } -template <> constexpr Type gettype() { return INT; } -template <> constexpr Type gettype() { return UINT; } -template <> constexpr Type gettype() { return INT; } -template <> constexpr Type gettype() { return UINT; } -template <> constexpr Type gettype() { +template <> constexpr Type get_type() { return BOOL; } +template <> constexpr Type get_type() { return INT; } +template <> constexpr Type get_type() { return UINT; } +template <> constexpr Type get_type() { return INT; } +template <> constexpr Type get_type() { return UINT; } +template <> constexpr Type get_type() { return sizeof(long) == sizeof(int) ? INT : LONG_LONG; } -template <> constexpr Type gettype() { - return sizeof(unsigned long) == sizeof(unsigned) ? - UINT : ULONG_LONG; +template <> constexpr Type get_type() { + return sizeof(unsigned long) == sizeof(unsigned) ? UINT : ULONG_LONG; } -template <> constexpr Type gettype() { return LONG_LONG; } -template <> constexpr Type gettype() { return ULONG_LONG; } -template <> constexpr Type gettype() { return DOUBLE; } -template <> constexpr Type gettype() { return DOUBLE; } -template <> constexpr Type gettype() { return LONG_DOUBLE; } -template <> constexpr Type gettype() { return INT; } -template <> constexpr Type gettype() { return UINT; } -template <> constexpr Type gettype() { return CHAR; } +template <> constexpr Type get_type() { return LONG_LONG; } +template <> constexpr Type get_type() { return ULONG_LONG; } +template <> constexpr Type get_type() { return DOUBLE; } +template <> constexpr Type get_type() { return DOUBLE; } +template <> constexpr Type get_type() { return LONG_DOUBLE; } +template <> constexpr Type get_type() { return INT; } +template <> constexpr Type get_type() { return UINT; } +template <> constexpr Type get_type() { return CHAR; } #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) -template <> constexpr Type gettype() { return CHAR; } +template <> constexpr Type get_type() { return CHAR; } #endif -template <> constexpr Type gettype() { return CSTRING; } -template <> constexpr Type gettype() { return CSTRING; } -template <> constexpr Type gettype() { return CSTRING; } -template <> constexpr Type gettype() { return CSTRING; } -template <> constexpr Type gettype() { return CSTRING; } -template <> constexpr Type gettype() { return CSTRING; } -template <> constexpr Type gettype() { return STRING; } -template <> constexpr Type gettype() { return STRING; } -template <> constexpr Type gettype() { return TSTRING; } -template <> constexpr Type gettype() { return TSTRING; } -template <> constexpr Type gettype() { return TSTRING; } -template <> constexpr Type gettype() { return TSTRING; } -template <> constexpr Type gettype() { return POINTER; } -template <> constexpr Type gettype() { return POINTER; } -template <> constexpr Type gettype() { return POINTER; } - -template -constexpr Type type() { return gettype::type>(); } +template <> constexpr Type get_type() { return CSTRING; } +template <> constexpr Type get_type() { return CSTRING; } +template <> constexpr Type get_type() { return CSTRING; } +template <> constexpr Type get_type() { return CSTRING; } +template <> constexpr Type get_type() { return CSTRING; } +template <> constexpr Type get_type() { return CSTRING; } +template <> constexpr Type get_type() { return STRING; } +template <> constexpr Type get_type() { return STRING; } +template <> constexpr Type get_type() { return TSTRING; } +template <> constexpr Type get_type() { return TSTRING; } +template <> constexpr Type get_type() { return TSTRING; } +template <> constexpr Type get_type() { return TSTRING; } +template <> constexpr Type get_type() { return POINTER; } +template <> constexpr Type get_type() { return POINTER; } +template <> constexpr Type get_type() { return POINTER; } // A formatting argument value. template @@ -1268,7 +1266,7 @@ class value { #define FMT_MAKE_VALUE_(Type, field, TYPE, rhs) \ value(Type value) { \ - static_assert(internal::type() == internal::TYPE, "invalid type"); \ + static_assert(get_type() == internal::TYPE, "invalid type"); \ this->field = rhs; \ } @@ -1309,14 +1307,14 @@ class value { #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) typedef typename wchar_helper::supported WChar; value(WChar value) { - static_assert(internal::type() == internal::CHAR, "invalid type"); + static_assert(get_type() == internal::CHAR, "invalid type"); this->int_value = value; } #endif #define FMT_MAKE_STR_VALUE(Type, TYPE) \ value(Type value) { \ - static_assert(internal::type() == internal::TYPE, "invalid type"); \ + static_assert(get_type() == internal::TYPE, "invalid type"); \ set_string(value); \ } @@ -1331,7 +1329,7 @@ class value { #define FMT_MAKE_WSTR_VALUE(Type, TYPE) \ value(typename wchar_helper::supported value) { \ - static_assert(internal::type() == internal::TYPE, "invalid type"); \ + static_assert(get_type() == internal::TYPE, "invalid type"); \ set_string(value); \ } @@ -1347,7 +1345,7 @@ class value { template value(const T &value, typename std::enable_if::value, int>::type = 0) { - static_assert(internal::type() == internal::CUSTOM, "invalid type"); + static_assert(get_type() == internal::CUSTOM, "invalid type"); this->custom.value = &value; this->custom.format = &format_custom_arg; } @@ -1355,7 +1353,7 @@ class value { template value(const T &value, typename std::enable_if::value, int>::type = 0) { - static_assert(internal::type() == internal::INT, "invalid type"); + static_assert(get_type() == internal::INT, "invalid type"); this->int_value = value; } @@ -1364,7 +1362,7 @@ class value { template value(const named_arg &value) { static_assert( - internal::type &>() == internal::NAMED_ARG, + get_type &>() == internal::NAMED_ARG, "invalid type"); this->pointer = &value; } @@ -1465,7 +1463,7 @@ namespace internal { template basic_arg make_arg(const T &value) { basic_arg arg; - arg.type_ = internal::type(); + arg.type_ = get_type(); arg.value_ = value; return arg; } @@ -1503,12 +1501,12 @@ struct named_arg : basic_arg { }; template -constexpr uint64_t make_type() { - return type() | (make_type() << 4); +constexpr uint64_t get_types() { + return get_type() | (get_types() << 4); } template <> -constexpr uint64_t make_type() { return 0; } +constexpr uint64_t get_types() { return 0; } // Maximum number of arguments with packed types. enum { MAX_PACKED_ARGS = 15 }; @@ -1546,7 +1544,7 @@ class arg_store { public: static const uint64_t TYPES = NUM_ARGS <= internal::MAX_PACKED_ARGS ? - internal::make_type() : -static_cast(NUM_ARGS); + internal::get_types() : -static_cast(NUM_ARGS); arg_store(const Args &... args) : data_(Array{{internal::make_arg(args)...}}) {} @@ -3494,10 +3492,10 @@ const Char *do_format_arg(basic_buffer &buffer, } // Specifies whether to format T using the standard formatter. -// It is not possible to use gettype in formatter specialization directly +// It is not possible to use get_type in formatter specialization directly // because of a bug in MSVC. template -struct format_type : std::integral_constant() != CUSTOM> {}; +struct format_type : std::integral_constant() != CUSTOM> {}; // Specifies whether to format enums. template @@ -3533,7 +3531,7 @@ struct formatter< auto it = internal::null_terminating_iterator(format); using handler_type = internal::dynamic_specs_handler; internal::specs_checker - handler(handler_type(specs_), internal::gettype()); + handler(handler_type(specs_), internal::get_type()); it = parse_format_specs(it, handler); return pointer_from(it); } @@ -3595,7 +3593,7 @@ struct dynamic_formatter { void on_hash() {} }; internal::specs_checker - checker(null_handler(), internal::gettype()); + checker(null_handler(), internal::get_type()); checker.on_align(specs_.align()); if (specs_.flags_ == 0) { // Do nothing.