Add underlying_t

This commit is contained in:
Victor Zverovich 2022-02-19 07:57:43 -08:00
parent af5d8004fc
commit 1319719a5e
2 changed files with 11 additions and 12 deletions

View File

@ -314,6 +314,8 @@ template <typename T>
using remove_cvref_t = typename std::remove_cv<remove_reference_t<T>>::type;
template <typename T> struct type_identity { using type = T; };
template <typename T> using type_identity_t = typename type_identity<T>::type;
template <typename T>
using underlying_t = typename std::underlying_type<T>::type;
struct monostate {
constexpr monostate() {}
@ -1416,8 +1418,8 @@ template <typename Context> struct arg_mapper {
!has_fallback_formatter<T, char_type>::value)>
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
-> decltype(std::declval<arg_mapper>().map(
static_cast<typename std::underlying_type<T>::type>(val))) {
return map(static_cast<typename std::underlying_type<T>::type>(val));
static_cast<underlying_t<T>>(val))) {
return map(static_cast<underlying_t<T>>(val));
}
template <typename T, typename U = decltype(format_as(T())),
@ -2214,13 +2216,12 @@ template <typename Char> constexpr bool is_ascii_letter(Char c) {
// Converts a character to ASCII. Returns a number > 127 on conversion failure.
template <typename Char, FMT_ENABLE_IF(std::is_integral<Char>::value)>
constexpr auto to_ascii(Char value) -> Char {
return value;
constexpr auto to_ascii(Char c) -> Char {
return c;
}
template <typename Char, FMT_ENABLE_IF(std::is_enum<Char>::value)>
constexpr auto to_ascii(Char value) ->
typename std::underlying_type<Char>::type {
return value;
constexpr auto to_ascii(Char c) -> underlying_t<Char> {
return c;
}
template <typename Char>

View File

@ -2354,8 +2354,7 @@ template <
type::custom_type,
FMT_ENABLE_IF(check)>
FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt {
return write<Char>(
out, static_cast<typename std::underlying_type<T>::type>(value));
return write<Char>(out, static_cast<underlying_t<T>>(value));
}
template <typename Char, typename OutputIt, typename T,
@ -2888,9 +2887,8 @@ template <typename T> auto ptr(const std::shared_ptr<T>& p) -> const void* {
\endrst
*/
template <typename Enum>
constexpr auto underlying(Enum e) noexcept ->
typename std::underlying_type<Enum>::type {
return static_cast<typename std::underlying_type<Enum>::type>(e);
constexpr auto underlying(Enum e) noexcept -> underlying_t<Enum> {
return static_cast<underlying_t<Enum>>(e);
}
#ifdef __cpp_lib_byte