resource: add operator==/!= to resource handles
This commit is contained in:
1
TODO
1
TODO
@@ -3,7 +3,6 @@
|
||||
* add examples (and credits) from @alanjfs :)
|
||||
|
||||
WIP:
|
||||
* resource handle: add comparison operators
|
||||
* get rid of storage_traits class template
|
||||
* uses-allocator construction: any (with allocator support), cache, poly, ...
|
||||
* add an ENTT_NOEXCEPT with args and use it to make ie compressed_pair conditionally noexcept
|
||||
|
||||
@@ -182,6 +182,24 @@ private:
|
||||
std::shared_ptr<value_type> resource;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Compares two handles.
|
||||
* @tparam Res Type of resource managed by the first handle.
|
||||
* @tparam Other Type of resource managed by the second handle.
|
||||
* @param lhs A valid handle.
|
||||
* @param rhs A valid handle.
|
||||
* @return True if both handles refer to the same resource, false otherwise.
|
||||
*/
|
||||
template<typename Res, typename Other>
|
||||
[[nodiscard]] bool operator==(const resource_handle<Res> &lhs, const resource_handle<Other> &rhs) ENTT_NOEXCEPT {
|
||||
return lhs.operator->() == rhs.operator->();
|
||||
}
|
||||
|
||||
template<typename ILhs, typename IRhs>
|
||||
[[nodiscard]] bool operator!=(const resource_handle<ILhs> &lhs, const resource_handle<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
} // namespace entt
|
||||
|
||||
#endif
|
||||
|
||||
@@ -151,6 +151,8 @@ TEST(Resource, ConstNonConstHandle) {
|
||||
static_assert(std::is_same_v<decltype(std::as_const(handle).get()), resource &>);
|
||||
|
||||
ASSERT_TRUE(chandle);
|
||||
ASSERT_EQ(handle, chandle);
|
||||
ASSERT_NE(handle, entt::resource_handle<resource>{});
|
||||
ASSERT_EQ(handle.use_count(), 2u);
|
||||
ASSERT_EQ(chandle->value, 42);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user