mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-30 15:32:36 +00:00
Add underlying_t
This commit is contained in:
parent
af5d8004fc
commit
1319719a5e
@ -314,6 +314,8 @@ template <typename T>
|
|||||||
using remove_cvref_t = typename std::remove_cv<remove_reference_t<T>>::type;
|
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> struct type_identity { using type = T; };
|
||||||
template <typename T> using type_identity_t = typename type_identity<T>::type;
|
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 {
|
struct monostate {
|
||||||
constexpr monostate() {}
|
constexpr monostate() {}
|
||||||
@ -1416,8 +1418,8 @@ template <typename Context> struct arg_mapper {
|
|||||||
!has_fallback_formatter<T, char_type>::value)>
|
!has_fallback_formatter<T, char_type>::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(
|
-> decltype(std::declval<arg_mapper>().map(
|
||||||
static_cast<typename std::underlying_type<T>::type>(val))) {
|
static_cast<underlying_t<T>>(val))) {
|
||||||
return map(static_cast<typename std::underlying_type<T>::type>(val));
|
return map(static_cast<underlying_t<T>>(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename U = decltype(format_as(T())),
|
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.
|
// Converts a character to ASCII. Returns a number > 127 on conversion failure.
|
||||||
template <typename Char, FMT_ENABLE_IF(std::is_integral<Char>::value)>
|
template <typename Char, FMT_ENABLE_IF(std::is_integral<Char>::value)>
|
||||||
constexpr auto to_ascii(Char value) -> Char {
|
constexpr auto to_ascii(Char c) -> Char {
|
||||||
return value;
|
return c;
|
||||||
}
|
}
|
||||||
template <typename Char, FMT_ENABLE_IF(std::is_enum<Char>::value)>
|
template <typename Char, FMT_ENABLE_IF(std::is_enum<Char>::value)>
|
||||||
constexpr auto to_ascii(Char value) ->
|
constexpr auto to_ascii(Char c) -> underlying_t<Char> {
|
||||||
typename std::underlying_type<Char>::type {
|
return c;
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
|
@ -2354,8 +2354,7 @@ template <
|
|||||||
type::custom_type,
|
type::custom_type,
|
||||||
FMT_ENABLE_IF(check)>
|
FMT_ENABLE_IF(check)>
|
||||||
FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt {
|
FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt {
|
||||||
return write<Char>(
|
return write<Char>(out, static_cast<underlying_t<T>>(value));
|
||||||
out, static_cast<typename std::underlying_type<T>::type>(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char, typename OutputIt, typename T,
|
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
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename Enum>
|
template <typename Enum>
|
||||||
constexpr auto underlying(Enum e) noexcept ->
|
constexpr auto underlying(Enum e) noexcept -> underlying_t<Enum> {
|
||||||
typename std::underlying_type<Enum>::type {
|
return static_cast<underlying_t<Enum>>(e);
|
||||||
return static_cast<typename std::underlying_type<Enum>::type>(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cpp_lib_byte
|
#ifdef __cpp_lib_byte
|
||||||
|
Loading…
x
Reference in New Issue
Block a user