stl: std::underlying_type_t

This commit is contained in:
skypjack
2026-04-02 10:09:36 +02:00
parent 8f411924b4
commit c60e076f80
4 changed files with 14 additions and 13 deletions
+5 -5
View File
@@ -48,19 +48,19 @@ concept enum_bitmask = std::is_enum_v<Type> && enum_as_bitmask_v<Type>;
*/
template<entt::enum_bitmask Type>
[[nodiscard]] constexpr Type operator|(const Type lhs, const Type rhs) noexcept {
return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) | static_cast<std::underlying_type_t<Type>>(rhs));
return static_cast<Type>(static_cast<stl::underlying_type_t<Type>>(lhs) | static_cast<stl::underlying_type_t<Type>>(rhs));
}
/*! @copydoc operator| */
template<entt::enum_bitmask Type>
[[nodiscard]] constexpr Type operator&(const Type lhs, const Type rhs) noexcept {
return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) & static_cast<std::underlying_type_t<Type>>(rhs));
return static_cast<Type>(static_cast<stl::underlying_type_t<Type>>(lhs) & static_cast<stl::underlying_type_t<Type>>(rhs));
}
/*! @copydoc operator| */
template<entt::enum_bitmask Type>
[[nodiscard]] constexpr Type operator^(const Type lhs, const Type rhs) noexcept {
return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) ^ static_cast<std::underlying_type_t<Type>>(rhs));
return static_cast<Type>(static_cast<stl::underlying_type_t<Type>>(lhs) ^ static_cast<stl::underlying_type_t<Type>>(rhs));
}
/**
@@ -72,13 +72,13 @@ template<entt::enum_bitmask Type>
*/
template<entt::enum_bitmask Type>
[[nodiscard]] constexpr Type operator~(const Type value) noexcept {
return static_cast<Type>(~static_cast<std::underlying_type_t<Type>>(value));
return static_cast<Type>(~static_cast<stl::underlying_type_t<Type>>(value));
}
/*! @copydoc operator~ */
template<entt::enum_bitmask Type>
[[nodiscard]] constexpr bool operator!(const Type value) noexcept {
return !static_cast<std::underlying_type_t<Type>>(value);
return !static_cast<stl::underlying_type_t<Type>>(value);
}
/*! @copydoc operator| */
+2 -2
View File
@@ -21,9 +21,9 @@ struct entt_traits;
template<typename Type>
requires requires {
requires std::is_enum_v<Type>;
typename internal::entt_traits<std::underlying_type_t<Type>>::value_type;
typename internal::entt_traits<stl::underlying_type_t<Type>>::value_type;
}
struct entt_traits<Type>: entt_traits<std::underlying_type_t<Type>> {
struct entt_traits<Type>: entt_traits<stl::underlying_type_t<Type>> {
using value_type = Type;
};
+6 -6
View File
@@ -46,16 +46,16 @@ enum class meta_traits : std::uint32_t {
template<typename Type>
requires std::is_enum_v<Type>
[[nodiscard]] auto meta_to_user_traits(const meta_traits traits) noexcept {
constexpr auto shift = std::popcount(static_cast<std::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits));
return Type{static_cast<std::underlying_type_t<Type>>(static_cast<std::underlying_type_t<meta_traits>>(traits) >> shift)};
constexpr auto shift = std::popcount(static_cast<stl::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits));
return Type{static_cast<stl::underlying_type_t<Type>>(static_cast<stl::underlying_type_t<meta_traits>>(traits) >> shift)};
}
template<typename Type>
requires std::is_enum_v<Type>
[[nodiscard]] auto user_to_meta_traits(const Type value) noexcept {
constexpr auto shift = std::popcount(static_cast<std::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits));
const auto traits = static_cast<std::underlying_type_t<internal::meta_traits>>(static_cast<std::underlying_type_t<Type>>(value));
ENTT_ASSERT(traits < ((~static_cast<std::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits)) >> shift), "Invalid traits");
constexpr auto shift = std::popcount(static_cast<stl::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits));
const auto traits = static_cast<stl::underlying_type_t<internal::meta_traits>>(static_cast<stl::underlying_type_t<Type>>(value));
ENTT_ASSERT(traits < ((~static_cast<stl::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits)) >> shift), "Invalid traits");
return meta_traits{traits << shift};
}
@@ -240,7 +240,7 @@ auto setup_node_for() noexcept {
};
} else if constexpr(std::is_enum_v<Type>) {
node.conversion_helper = +[](void *lhs, const void *rhs) {
return lhs ? static_cast<double>(*static_cast<Type *>(lhs) = static_cast<Type>(static_cast<std::underlying_type_t<Type>>(*static_cast<const double *>(rhs)))) : static_cast<double>(*static_cast<const Type *>(rhs));
return lhs ? static_cast<double>(*static_cast<Type *>(lhs) = static_cast<Type>(static_cast<stl::underlying_type_t<Type>>(*static_cast<const double *>(rhs)))) : static_cast<double>(*static_cast<const Type *>(rhs));
};
}
+1
View File
@@ -31,6 +31,7 @@ using std::remove_cvref_t;
using std::remove_pointer_t;
using std::remove_reference_t;
using std::true_type;
using std::underlying_type_t;
} // namespace entt::stl
/*! @endcond */