stl: std::underlying_type_t
This commit is contained in:
@@ -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| */
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user