upd: [imp] enum_cast => underlyof

This commit is contained in:
mutouyun 2023-05-20 17:06:16 +08:00
parent 426b7c3768
commit ce04c79112
4 changed files with 10 additions and 9 deletions

View File

@ -15,7 +15,7 @@
#include "libimp/def.h" #include "libimp/def.h"
#include "libimp/detect_plat.h" #include "libimp/detect_plat.h"
#include "libimp/export.h" #include "libimp/export.h"
#include "libimp/enum_cast.h" #include "libimp/underlyof.h"
#include "libimp/fmt.h" #include "libimp/fmt.h"
#include "libimp/generic.h" #include "libimp/generic.h"
@ -60,7 +60,7 @@ bool context_to_string(fmt_context &f_ctx, context<T...> const &l_ctx) noexcept
LIBIMP_TRY { LIBIMP_TRY {
auto ms = std::chrono::time_point_cast<std::chrono::milliseconds>(l_ctx.tp).time_since_epoch().count() % 1000; auto ms = std::chrono::time_point_cast<std::chrono::milliseconds>(l_ctx.tp).time_since_epoch().count() % 1000;
return detail::unfold_tuple_fmt_to(f_ctx, l_ctx.params, std::index_sequence_for<T...>{}, return detail::unfold_tuple_fmt_to(f_ctx, l_ctx.params, std::index_sequence_for<T...>{},
"[", types[enum_cast(l_ctx.level)], "]" "[", types[underlyof(l_ctx.level)], "]"
"[", l_ctx.tp, ".", spec("03")(ms), "]" "[", l_ctx.tp, ".", spec("03")(ms), "]"
"[", l_ctx.func, "] "); "[", l_ctx.func, "] ");
} LIBIMP_CATCH(...) { } LIBIMP_CATCH(...) {
@ -185,7 +185,7 @@ class grip {
template <typename... A> template <typename... A>
grip &output(log::level l, A &&... args) noexcept { grip &output(log::level l, A &&... args) noexcept {
if (!printer_ || (enum_cast(l) < enum_cast(level_limit_))) { if (!printer_ || (underlyof(l) < underlyof(level_limit_))) {
return *this; return *this;
} }
printer_.output(context<A &&...> { printer_.output(context<A &&...> {

View File

@ -1,5 +1,5 @@
/** /**
* \file libimp/enum_cast.h * \file libimp/underlyof.h
* \author mutouyun (orz@orzz.org) * \author mutouyun (orz@orzz.org)
* \brief Returns the underlying type of the given enum * \brief Returns the underlying type of the given enum
* \date 2022-03-01 * \date 2022-03-01
@ -14,8 +14,9 @@ LIBIMP_NAMESPACE_BEG_
/// \brief Returns after converting the value to the underlying type of E. /// \brief Returns after converting the value to the underlying type of E.
/// \see https://en.cppreference.com/w/cpp/types/underlying_type /// \see https://en.cppreference.com/w/cpp/types/underlying_type
/// https://en.cppreference.com/w/cpp/utility/to_underlying
template <typename E> template <typename E>
constexpr auto enum_cast(E e) noexcept { constexpr auto underlyof(E e) noexcept {
return static_cast<std::underlying_type_t<E>>(e); return static_cast<std::underlying_type_t<E>>(e);
} }

View File

@ -71,11 +71,11 @@ result<std::int64_t> conf(info r) noexcept {
break; break;
} }
default: default:
log.error("invalid info = ", enum_cast(r)); log.error("invalid info = ", underlyof(r));
return {}; return {};
} }
auto err = sys::error(); auto err = sys::error();
log.error("info = ", enum_cast(r), ", error = ", err); log.error("info = ", underlyof(r), ", error = ", err);
return {false, (int)err.code()}; return {false, (int)err.code()};
} }

View File

@ -14,7 +14,7 @@
#include "libimp/system.h" #include "libimp/system.h"
#include "libimp/log.h" #include "libimp/log.h"
#include "libimp/codecvt.h" #include "libimp/codecvt.h"
#include "libimp/enum_cast.h" #include "libimp/underlyof.h"
#include "libimp/detect_plat.h" #include "libimp/detect_plat.h"
LIBIMP_NAMESPACE_BEG_ LIBIMP_NAMESPACE_BEG_
@ -94,7 +94,7 @@ result<std::int64_t> conf(info r) noexcept {
return (std::int64_t)info.dwPageSize; return (std::int64_t)info.dwPageSize;
} }
default: default:
log.error("invalid info = ", enum_cast(r)); log.error("invalid info = ", underlyof(r));
return {}; return {};
} }
} }