Make arg_mapper SFINAE-friendly again
This commit is contained in:
parent
e2408f37c8
commit
b41890c1e5
@ -1282,6 +1282,15 @@ inline auto format_as(std::byte b) -> unsigned char {
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T> struct has_format_as {
|
||||
template <typename U, typename V = decltype(format_as(U())),
|
||||
FMT_ENABLE_IF(std::is_enum<U>::value&& std::is_integral<V>::value)>
|
||||
static auto check(U*) -> std::true_type;
|
||||
static auto check(...) -> std::false_type;
|
||||
|
||||
enum { value = decltype(check(static_cast<T*>(nullptr)))::value };
|
||||
};
|
||||
|
||||
// Maps formatting arguments to core types.
|
||||
// arg_mapper reports errors by returning unformattable instead of using
|
||||
// static_assert because it's used in the is_formattable trait.
|
||||
@ -1436,11 +1445,10 @@ template <typename Context> struct arg_mapper {
|
||||
return map(static_cast<underlying_t<T>>(val));
|
||||
}
|
||||
|
||||
template <typename T, typename U = decltype(format_as(T())),
|
||||
FMT_ENABLE_IF(std::is_enum<T>::value&& std::is_integral<U>::value)>
|
||||
template <typename T, FMT_ENABLE_IF(has_format_as<T>::value &&
|
||||
!has_formatter<T, Context>::value)>
|
||||
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
|
||||
-> decltype(std::declval<arg_mapper>().map(U())) {
|
||||
static_assert(!has_formatter<T, Context>::value, "");
|
||||
-> decltype(std::declval<arg_mapper>().map(format_as(T()))) {
|
||||
return map(format_as(val));
|
||||
}
|
||||
|
||||
@ -1470,6 +1478,7 @@ template <typename Context> struct arg_mapper {
|
||||
template <typename T, typename U = remove_cvref_t<T>,
|
||||
FMT_ENABLE_IF(!is_string<U>::value && !is_char<U>::value &&
|
||||
!std::is_array<U>::value &&
|
||||
!has_format_as<U>::value &&
|
||||
(has_formatter<U, Context>::value ||
|
||||
has_fallback_formatter<U, char_type>::value))>
|
||||
FMT_CONSTEXPR FMT_INLINE auto map(T&& val)
|
||||
|
Loading…
Reference in New Issue
Block a user