diff --git a/docs/md/core.md b/docs/md/core.md index 17e60cf0f..3536a25b8 100644 --- a/docs/md/core.md +++ b/docs/md/core.md @@ -559,9 +559,8 @@ require to enable RTTI.
Therefore, they can sometimes be even more reliable than those obtained otherwise. -Its type defines a default constructible opaque class that is also copyable and -movable.
-Objects of this class are generally returned by the `type_id` functions: +Its type defines an opaque class that is also copyable and movable.
+Objects of this type are generally returned by the `type_id` functions: ```cpp // by type @@ -571,11 +570,16 @@ auto info = entt::type_id(); auto other = entt::type_id(42); ``` -The objects thus received are nothing more than const references to instances of -`type_info` with static storage duration.
+All elements thus received are nothing more than const references to instances +of `type_info` with static storage duration.
This is convenient for saving the entire object aside for the cost of a pointer. -However, nothing prevents from constructing `type_info` objects directly.
-These are the information made available by this kind of objects: +However, nothing prevents from constructing `type_info` objects directly: + +```cpp +entt::type_info info{std::in_place_type}; +``` + +These are the information made available by `type_info`: * The index associated with a given type: diff --git a/src/entt/core/type_info.hpp b/src/entt/core/type_info.hpp index 73243f3d1..bcae91126 100644 --- a/src/entt/core/type_info.hpp +++ b/src/entt/core/type_info.hpp @@ -21,8 +21,7 @@ namespace internal { struct ENTT_API type_index final { [[nodiscard]] static id_type next() ENTT_NOEXCEPT { static ENTT_MAYBE_ATOMIC(id_type) value{}; - // 0u is reserved for empty type_info objects - return ++value; + return value++; } }; @@ -140,12 +139,6 @@ struct type_name final { /*! @brief Implementation specific information about a type. */ struct type_info final { - /*! @brief Default constructor. */ - constexpr type_info() ENTT_NOEXCEPT - : seq{}, - identifier{}, - alias{} {} - /** * @brief Constructs a type info object for a given type. * @tparam Type Type for which to construct a type info object. @@ -154,9 +147,7 @@ struct type_info final { constexpr type_info(std::in_place_type_t) ENTT_NOEXCEPT : seq{type_index>>::value()}, identifier{type_hash>>::value()}, - alias{type_name>>::value()} { - ENTT_ASSERT(seq != 0u, "Invalid type index"); - } + alias{type_name>>::value()} {} /** * @brief Type index. @@ -182,14 +173,6 @@ struct type_info final { return alias; } - /** - * @brief Returns true if properly initialized, false otherwise. - * @return True if properly initialized, false otherwise. - */ - [[nodiscard]] explicit constexpr operator bool() const ENTT_NOEXCEPT { - return (seq != 0u); - } - private: id_type seq; id_type identifier; diff --git a/test/entt/core/type_info.cpp b/test/entt/core/type_info.cpp index 84f238880..aca2e227a 100644 --- a/test/entt/core/type_info.cpp +++ b/test/entt/core/type_info.cpp @@ -84,16 +84,6 @@ TEST(TypeInfo, Functionalities) { ASSERT_EQ(other.name(), info.name()); } -TEST(TypeInfo, Validity) { - entt::type_info info{}; - entt::type_info other = entt::type_id(); - - ASSERT_FALSE(info); - ASSERT_TRUE(other); - ASSERT_EQ(info.index(), 0u); - ASSERT_NE(other.index(), 0u); -} - TEST(TypeInfo, Order) { entt::type_info rhs = entt::type_id(); entt::type_info lhs = entt::type_id();