diff --git a/include/libimp/log.h b/include/libimp/log.h index 97958ee..33c38d2 100644 --- a/include/libimp/log.h +++ b/include/libimp/log.h @@ -15,7 +15,7 @@ #include "libimp/def.h" #include "libimp/detect_plat.h" #include "libimp/export.h" -#include "libimp/enum_cast.h" +#include "libimp/underlyof.h" #include "libimp/fmt.h" #include "libimp/generic.h" @@ -60,7 +60,7 @@ bool context_to_string(fmt_context &f_ctx, context const &l_ctx) noexcept LIBIMP_TRY { auto ms = std::chrono::time_point_cast(l_ctx.tp).time_since_epoch().count() % 1000; return detail::unfold_tuple_fmt_to(f_ctx, l_ctx.params, std::index_sequence_for{}, - "[", types[enum_cast(l_ctx.level)], "]" + "[", types[underlyof(l_ctx.level)], "]" "[", l_ctx.tp, ".", spec("03")(ms), "]" "[", l_ctx.func, "] "); } LIBIMP_CATCH(...) { @@ -185,7 +185,7 @@ class grip { template 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; } printer_.output(context { diff --git a/include/libimp/enum_cast.h b/include/libimp/underlyof.h similarity index 77% rename from include/libimp/enum_cast.h rename to include/libimp/underlyof.h index 4b6e01d..edef44f 100644 --- a/include/libimp/enum_cast.h +++ b/include/libimp/underlyof.h @@ -1,5 +1,5 @@ /** - * \file libimp/enum_cast.h + * \file libimp/underlyof.h * \author mutouyun (orz@orzz.org) * \brief Returns the underlying type of the given enum * \date 2022-03-01 @@ -14,8 +14,9 @@ LIBIMP_NAMESPACE_BEG_ /// \brief Returns after converting the value to the underlying type of E. /// \see https://en.cppreference.com/w/cpp/types/underlying_type +/// https://en.cppreference.com/w/cpp/utility/to_underlying template -constexpr auto enum_cast(E e) noexcept { +constexpr auto underlyof(E e) noexcept { return static_cast>(e); } diff --git a/src/libimp/platform/posix/system.h b/src/libimp/platform/posix/system.h index 0c9ec9c..fab18b7 100644 --- a/src/libimp/platform/posix/system.h +++ b/src/libimp/platform/posix/system.h @@ -71,11 +71,11 @@ result conf(info r) noexcept { break; } default: - log.error("invalid info = ", enum_cast(r)); + log.error("invalid info = ", underlyof(r)); return {}; } auto err = sys::error(); - log.error("info = ", enum_cast(r), ", error = ", err); + log.error("info = ", underlyof(r), ", error = ", err); return {false, (int)err.code()}; } diff --git a/src/libimp/platform/win/system.h b/src/libimp/platform/win/system.h index 9cfe4ab..8d59e08 100644 --- a/src/libimp/platform/win/system.h +++ b/src/libimp/platform/win/system.h @@ -14,7 +14,7 @@ #include "libimp/system.h" #include "libimp/log.h" #include "libimp/codecvt.h" -#include "libimp/enum_cast.h" +#include "libimp/underlyof.h" #include "libimp/detect_plat.h" LIBIMP_NAMESPACE_BEG_ @@ -94,7 +94,7 @@ result conf(info r) noexcept { return (std::int64_t)info.dwPageSize; } default: - log.error("invalid info = ", enum_cast(r)); + log.error("invalid info = ", underlyof(r)); return {}; } }