type_info: a more reliable operator bool

This commit is contained in:
Michele Caini
2021-03-12 09:33:42 +01:00
parent a4d16bffd3
commit 4162d4fbc6
2 changed files with 13 additions and 4 deletions

View File

@@ -38,7 +38,7 @@ template<typename Type>
auto value = pretty_function.substr(first, pretty_function.find_last_of(ENTT_PRETTY_FUNCTION_SUFFIX) - first);
return value;
#else
return std::string_view{};
return std::string_view{""};
#endif
}
@@ -185,7 +185,7 @@ public:
* @return True if the object is properly initialized, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return !name_value.empty();
return name_value.data() != nullptr;
}
/**

View File

@@ -5,6 +5,13 @@
#include <entt/core/type_info.hpp>
#include <entt/core/type_traits.hpp>
template<>
struct entt::type_name<float> final {
[[nodiscard]] static constexpr std::string_view value() ENTT_NOEXCEPT {
return std::string_view{""};
}
};
TEST(TypeSeq, Functionalities) {
ASSERT_EQ(entt::type_seq<int>::value(), entt::type_seq<int>::value());
ASSERT_NE(entt::type_seq<int>::value(), entt::type_seq<char>::value());
@@ -44,7 +51,8 @@ TEST(TypeInfo, Functionalities) {
ASSERT_NE(entt::type_id<int>(), entt::type_info{});
ASSERT_NE(entt::type_id<int>(), entt::type_id<char>());
auto info = entt::type_id<int>();
const auto info = entt::type_id<int>();
const auto unnamed = entt::type_id<float>();
entt::type_info empty{};
ASSERT_NE(info, empty);
@@ -55,8 +63,9 @@ TEST(TypeInfo, Functionalities) {
ASSERT_EQ(info.hash(), entt::type_hash<int>::value());
ASSERT_EQ(info.name(), entt::type_name<int>::value());
ASSERT_FALSE(empty);
ASSERT_TRUE(info);
ASSERT_TRUE(unnamed);
ASSERT_FALSE(empty);
empty = info;