resource: swap
This commit is contained in:
1
TODO
1
TODO
@@ -45,4 +45,3 @@ TODO:
|
||||
* view and view iterator specializations for multi, single and filtered elements
|
||||
* organizer support to groups
|
||||
* meta range: move id to meta objects and return plain types (?), then remove id from meta base and meta ctor too
|
||||
* resource: swap support
|
||||
|
||||
@@ -116,6 +116,15 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Exchanges the content with that of a given resource.
|
||||
* @param other Resource to exchange the content with.
|
||||
*/
|
||||
void swap(resource &other) {
|
||||
using std::swap;
|
||||
swap(value, other.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a reference to the managed resource.
|
||||
*
|
||||
|
||||
@@ -70,6 +70,31 @@ TEST(Resource, Functionalities) {
|
||||
ASSERT_NE(copy, move);
|
||||
}
|
||||
|
||||
TEST(Resource, Swap) {
|
||||
entt::resource<int> resource{};
|
||||
entt::resource<int> other{};
|
||||
|
||||
ASSERT_FALSE(resource);
|
||||
ASSERT_FALSE(other);
|
||||
|
||||
resource.swap(other);
|
||||
|
||||
ASSERT_FALSE(resource);
|
||||
ASSERT_FALSE(other);
|
||||
|
||||
resource.reset(std::make_shared<int>(1));
|
||||
|
||||
ASSERT_TRUE(resource);
|
||||
ASSERT_EQ(*resource, 1);
|
||||
ASSERT_FALSE(other);
|
||||
|
||||
resource.swap(other);
|
||||
|
||||
ASSERT_FALSE(resource);
|
||||
ASSERT_TRUE(other);
|
||||
ASSERT_EQ(*other, 1);
|
||||
}
|
||||
|
||||
TEST(Resource, DerivedToBase) {
|
||||
const entt::resource<derived> resource{std::make_shared<derived>()};
|
||||
entt::resource<base> other{resource};
|
||||
|
||||
Reference in New Issue
Block a user