sparse_set/storage: swap based move assignment operator

This commit is contained in:
Michele Caini
2024-09-06 15:24:21 +02:00
parent c3826c78aa
commit 9f36bec353
9 changed files with 11 additions and 23 deletions

2
TODO
View File

@@ -45,4 +45,4 @@ 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
* noexcept move op for sparse set and storage
* review all move assignment operators

View File

@@ -151,11 +151,7 @@ public:
* @return This mixin.
*/
basic_sigh_mixin &operator=(basic_sigh_mixin &&other) noexcept(noexcept(std::declval<underlying_type>().operator=(std::move(other)))) {
owner = other.owner;
construction = std::move(other.construction);
destruction = std::move(other.destruction);
update = std::move(other.update);
underlying_type::operator=(std::move(other));
swap(other);
return *this;
}

View File

@@ -468,15 +468,9 @@ public:
* @param other The instance to move from.
* @return This sparse set.
*/
basic_sparse_set &operator=(basic_sparse_set &&other) noexcept(false) {
basic_sparse_set &operator=(basic_sparse_set &&other) noexcept {
ENTT_ASSERT(alloc_traits::is_always_equal::value || get_allocator() == other.get_allocator(), "Copying a sparse set is not allowed");
release_sparse_pages();
sparse = std::move(other.sparse);
packed = std::move(other.packed);
info = other.info;
mode = other.mode;
head = std::exchange(other.head, policy_to_head());
swap(other);
return *this;
}

View File

@@ -476,11 +476,9 @@ public:
* @param other The instance to move from.
* @return This storage.
*/
basic_storage &operator=(basic_storage &&other) noexcept(false) {
basic_storage &operator=(basic_storage &&other) noexcept {
ENTT_ASSERT(alloc_traits::is_always_equal::value || get_allocator() == other.get_allocator(), "Copying a storage is not allowed");
shrink_to_size(0u);
payload = std::move(other.payload);
base_type::operator=(std::move(other));
swap(other);
return *this;
}

View File

@@ -343,7 +343,7 @@ TYPED_TEST(SighMixin, Move) {
other = std::move(pool);
test::is_initialized(pool);
ASSERT_TRUE(pool.empty());
ASSERT_FALSE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.index(entt::entity{3}), 0u);

View File

@@ -128,7 +128,7 @@ TYPED_TEST(SparseSet, Move) {
other = std::move(set);
test::is_initialized(set);
ASSERT_TRUE(set.empty());
ASSERT_FALSE(set.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.policy(), policy);

View File

@@ -151,7 +151,7 @@ TYPED_TEST(Storage, Move) {
other = std::move(pool);
test::is_initialized(pool);
ASSERT_TRUE(pool.empty());
ASSERT_FALSE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<value_type>());

View File

@@ -71,7 +71,7 @@ TEST(StorageEntity, Move) {
other = std::move(pool);
test::is_initialized(pool);
ASSERT_TRUE(pool.empty());
ASSERT_FALSE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<void>());

View File

@@ -116,7 +116,7 @@ TYPED_TEST(StorageNoInstance, Move) {
other = std::move(pool);
test::is_initialized(pool);
ASSERT_TRUE(pool.empty());
ASSERT_FALSE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<value_type>());