type_info: add conversion operators to underlying types (close #664)
This commit is contained in:
@@ -97,6 +97,9 @@ struct ENTT_API type_seq final {
|
||||
static const id_type value = internal::type_seq::next();
|
||||
return value;
|
||||
}
|
||||
|
||||
/*! @brief Conversion operator to the underlying type. */
|
||||
[[nodiscard]] constexpr operator id_type() const ENTT_NOEXCEPT { return value(); }
|
||||
};
|
||||
|
||||
|
||||
@@ -118,6 +121,9 @@ struct type_hash final {
|
||||
return type_seq<Type>::value();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*! @brief Conversion operator to the underlying type. */
|
||||
[[nodiscard]] constexpr operator id_type() const ENTT_NOEXCEPT { return value(); }
|
||||
};
|
||||
|
||||
|
||||
@@ -134,6 +140,9 @@ struct type_name final {
|
||||
[[nodiscard]] static constexpr std::string_view value() ENTT_NOEXCEPT {
|
||||
return internal::type_name<Type>(0);
|
||||
}
|
||||
|
||||
/*! @brief Conversion operator to the underlying type. */
|
||||
[[nodiscard]] constexpr operator std::string_view() const ENTT_NOEXCEPT { return value(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,12 +10,14 @@ TEST(TypeSeq, Functionalities) {
|
||||
ASSERT_NE(entt::type_seq<int>::value(), entt::type_seq<char>::value());
|
||||
ASSERT_NE(entt::type_seq<int>::value(), entt::type_seq<int &&>::value());
|
||||
ASSERT_NE(entt::type_seq<int &>::value(), entt::type_seq<const int &>::value());
|
||||
ASSERT_EQ(static_cast<entt::id_type>(entt::type_seq<int>{}), entt::type_seq<int>::value());
|
||||
}
|
||||
|
||||
TEST(TypeHash, Functionalities) {
|
||||
ASSERT_NE(entt::type_hash<int>::value(), entt::type_hash<const int>::value());
|
||||
ASSERT_NE(entt::type_hash<int>::value(), entt::type_hash<char>::value());
|
||||
ASSERT_EQ(entt::type_hash<int>::value(), entt::type_hash<int>::value());
|
||||
ASSERT_EQ(static_cast<entt::id_type>(entt::type_hash<int>{}), entt::type_hash<int>::value());
|
||||
}
|
||||
|
||||
TEST(TypeName, Functionalities) {
|
||||
@@ -27,6 +29,8 @@ TEST(TypeName, Functionalities) {
|
||||
|
||||
ASSERT_TRUE(((entt::type_name<entt::type_list<entt::type_list<int, char>, double>>::value()) == std::string_view{"entt::type_list<entt::type_list<int, char>, double>"})
|
||||
|| ((entt::type_name<entt::type_list<entt::type_list<int, char>, double>>::value()) == std::string_view{"struct entt::type_list<struct entt::type_list<int,char>,double>"}));
|
||||
|
||||
ASSERT_EQ(static_cast<std::string_view>(entt::type_name<int>{}), entt::type_name<int>::value());
|
||||
}
|
||||
|
||||
TEST(TypeInfo, Functionalities) {
|
||||
|
||||
Reference in New Issue
Block a user