mirror of
https://github.com/fmtlib/fmt.git
synced 2025-03-29 01:20:23 +00:00
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
|
#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.
|
// Maps formatting arguments to core types.
|
||||||
// arg_mapper reports errors by returning unformattable instead of using
|
// arg_mapper reports errors by returning unformattable instead of using
|
||||||
// static_assert because it's used in the is_formattable trait.
|
// 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));
|
return map(static_cast<underlying_t<T>>(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename U = decltype(format_as(T())),
|
template <typename T, FMT_ENABLE_IF(has_format_as<T>::value &&
|
||||||
FMT_ENABLE_IF(std::is_enum<T>::value&& std::is_integral<U>::value)>
|
!has_formatter<T, Context>::value)>
|
||||||
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
|
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
|
||||||
-> decltype(std::declval<arg_mapper>().map(U())) {
|
-> decltype(std::declval<arg_mapper>().map(format_as(T()))) {
|
||||||
static_assert(!has_formatter<T, Context>::value, "");
|
|
||||||
return map(format_as(val));
|
return map(format_as(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1470,6 +1478,7 @@ template <typename Context> struct arg_mapper {
|
|||||||
template <typename T, typename U = remove_cvref_t<T>,
|
template <typename T, typename U = remove_cvref_t<T>,
|
||||||
FMT_ENABLE_IF(!is_string<U>::value && !is_char<U>::value &&
|
FMT_ENABLE_IF(!is_string<U>::value && !is_char<U>::value &&
|
||||||
!std::is_array<U>::value &&
|
!std::is_array<U>::value &&
|
||||||
|
!has_format_as<U>::value &&
|
||||||
(has_formatter<U, Context>::value ||
|
(has_formatter<U, Context>::value ||
|
||||||
has_fallback_formatter<U, char_type>::value))>
|
has_fallback_formatter<U, char_type>::value))>
|
||||||
FMT_CONSTEXPR FMT_INLINE auto map(T&& val)
|
FMT_CONSTEXPR FMT_INLINE auto map(T&& val)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user