any: try to also please gcc7
This commit is contained in:
@@ -181,10 +181,10 @@ const std::size_t hash = any.hash();
|
||||
However, there are some limitations:
|
||||
|
||||
* The instance of `any` **must** not be empty, otherwise the returned value is
|
||||
that of `std::hash<std::nullptr_t>{}({})`.
|
||||
that of `std::hash<const void *>{}(nullptr)`.
|
||||
|
||||
* The underlying object **must** support this operation, otherwise the returned
|
||||
value is that of `std::hash<std::nullptr_t>{}({})`.
|
||||
value is that of `std::hash<const void *>{}(nullptr)`.
|
||||
|
||||
Unfortunately, it's not possible to trigger a compile-time error in these cases.
|
||||
This would prevent users from using non-hashable types with `any`.<br/>
|
||||
|
||||
@@ -395,14 +395,14 @@ public:
|
||||
* returned once converted to `const void *`.
|
||||
*
|
||||
* @return The hash value of the contained object or its address if any,
|
||||
* `std::hash<std::nullptr_t>{}({})` otherwise.
|
||||
* `std::hash<const void *>{}({})` otherwise.
|
||||
*/
|
||||
[[nodiscard]] std::size_t hash() const ENTT_NOEXCEPT {
|
||||
if(std::size_t value{}; vtable && vtable(operation::hash, *this, &value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return std::hash<std::nullptr_t>{}({});
|
||||
return std::hash<const void *>{}(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -1192,8 +1192,8 @@ TEST_F(Any, NotHashable) {
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(ref);
|
||||
|
||||
ASSERT_EQ(any.hash(), std::hash<std::nullptr_t>{}({}));
|
||||
ASSERT_EQ(std::hash<std::nullptr_t>{}({}), std::hash<entt::any>{}(ref));
|
||||
ASSERT_EQ(any.hash(), std::hash<const void *>{}(nullptr));
|
||||
ASSERT_EQ(std::hash<const void *>{}(nullptr), std::hash<entt::any>{}(ref));
|
||||
ASSERT_EQ(ref.hash(), std::hash<entt::any>{}(any));
|
||||
ASSERT_EQ(any.hash(), entt::any{}.hash());
|
||||
}
|
||||
|
||||
@@ -1097,8 +1097,8 @@ TEST_F(MetaAny, NotHashable) {
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(ref);
|
||||
|
||||
ASSERT_EQ(any.hash(), std::hash<std::nullptr_t>{}({}));
|
||||
ASSERT_EQ(std::hash<std::nullptr_t>{}({}), std::hash<entt::any>{}(ref));
|
||||
ASSERT_EQ(any.hash(), std::hash<const void *>{}(nullptr));
|
||||
ASSERT_EQ(std::hash<const void *>{}(nullptr), std::hash<entt::any>{}(ref));
|
||||
ASSERT_EQ(ref.hash(), std::hash<entt::any>{}(any));
|
||||
ASSERT_EQ(any.hash(), entt::any{}.hash());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user