meta: add meta_type::is_integral and meta_type::is_signed (close #884)
This commit is contained in:
@@ -1025,6 +1025,22 @@ public:
|
||||
return !!(node->traits & internal::meta_traits::is_arithmetic);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether a type refers to an integral type or not.
|
||||
* @return True if the underlying type is an integral type, false otherwise.
|
||||
*/
|
||||
[[nodiscard]] bool is_integral() const noexcept {
|
||||
return !!(node->traits & internal::meta_traits::is_integral);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether a type refers to a signed type or not.
|
||||
* @return True if the underlying type is a signed type, false otherwise.
|
||||
*/
|
||||
[[nodiscard]] bool is_signed() const noexcept {
|
||||
return !!(node->traits & internal::meta_traits::is_signed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether a type refers to an array type or not.
|
||||
* @return True if the underlying type is an array type, false otherwise.
|
||||
|
||||
@@ -29,13 +29,15 @@ enum class meta_traits : std::uint32_t {
|
||||
is_const = 0x0001,
|
||||
is_static = 0x0002,
|
||||
is_arithmetic = 0x0004,
|
||||
is_array = 0x0008,
|
||||
is_enum = 0x0010,
|
||||
is_class = 0x0020,
|
||||
is_pointer = 0x0040,
|
||||
is_meta_pointer_like = 0x0080,
|
||||
is_meta_sequence_container = 0x0100,
|
||||
is_meta_associative_container = 0x0200,
|
||||
is_integral = 0x0008,
|
||||
is_signed = 0x0010,
|
||||
is_array = 0x0020,
|
||||
is_enum = 0x0040,
|
||||
is_class = 0x0080,
|
||||
is_pointer = 0x0100,
|
||||
is_meta_pointer_like = 0x0200,
|
||||
is_meta_sequence_container = 0x0400,
|
||||
is_meta_associative_container = 0x0800,
|
||||
_entt_enum_as_bitmask
|
||||
};
|
||||
|
||||
@@ -170,6 +172,8 @@ public:
|
||||
{},
|
||||
internal::meta_traits::is_none
|
||||
| (std::is_arithmetic_v<Type> ? internal::meta_traits::is_arithmetic : internal::meta_traits::is_none)
|
||||
| (std::is_integral_v<Type> ? internal::meta_traits::is_integral : internal::meta_traits::is_none)
|
||||
| (std::is_signed_v<Type> ? internal::meta_traits::is_signed : internal::meta_traits::is_none)
|
||||
| (std::is_array_v<Type> ? internal::meta_traits::is_array : internal::meta_traits::is_none)
|
||||
| (std::is_enum_v<Type> ? internal::meta_traits::is_enum : internal::meta_traits::is_none)
|
||||
| (std::is_class_v<Type> ? internal::meta_traits::is_class : internal::meta_traits::is_none)
|
||||
|
||||
@@ -235,6 +235,14 @@ TEST_F(MetaType, Traits) {
|
||||
ASSERT_TRUE(entt::resolve<double>().is_arithmetic());
|
||||
ASSERT_FALSE(entt::resolve<clazz_t>().is_arithmetic());
|
||||
|
||||
ASSERT_TRUE(entt::resolve<int>().is_integral());
|
||||
ASSERT_FALSE(entt::resolve<double>().is_integral());
|
||||
ASSERT_FALSE(entt::resolve<clazz_t>().is_integral());
|
||||
|
||||
ASSERT_TRUE(entt::resolve<long>().is_signed());
|
||||
ASSERT_FALSE(entt::resolve<unsigned int>().is_signed());
|
||||
ASSERT_FALSE(entt::resolve<clazz_t>().is_signed());
|
||||
|
||||
ASSERT_TRUE(entt::resolve<int[5]>().is_array());
|
||||
ASSERT_TRUE(entt::resolve<int[5][3]>().is_array());
|
||||
ASSERT_FALSE(entt::resolve<int>().is_array());
|
||||
|
||||
Reference in New Issue
Block a user