Skip to content

Commit

Permalink
sparse_set/storage: swap based move assignment operator
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Sep 6, 2024
1 parent c3826c7 commit 9f36bec
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 23 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions src/entt/entity/mixin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@ class basic_sigh_mixin final: public Type {
* @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;
}

Expand Down
10 changes: 2 additions & 8 deletions src/entt/entity/sparse_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,9 @@ class basic_sparse_set {
* @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;
}

Expand Down
6 changes: 2 additions & 4 deletions src/entt/entity/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,9 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
* @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;
}

Expand Down
2 changes: 1 addition & 1 deletion test/entt/entity/sigh_mixin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/entt/entity/sparse_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/entt/entity/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>());
Expand Down
2 changes: 1 addition & 1 deletion test/entt/entity/storage_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>());
Expand Down
2 changes: 1 addition & 1 deletion test/entt/entity/storage_no_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>());
Expand Down

0 comments on commit 9f36bec

Please sign in to comment.