Skip to content

Commit 20ab2e9

Browse files
authored
vector: fix move-assignment (#251)
Move-assignment with the rvalue reference to the object itself should be no-op.
1 parent eb5de4a commit 20ab2e9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

include/cista/containers/vector.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ struct basic_vector {
7878
}
7979

8080
basic_vector& operator=(basic_vector&& arr) noexcept {
81-
deallocate();
81+
if (&arr != this) {
82+
deallocate();
8283

83-
el_ = arr.el_;
84-
used_size_ = arr.used_size_;
85-
self_allocated_ = arr.self_allocated_;
86-
allocated_size_ = arr.allocated_size_;
84+
el_ = arr.el_;
85+
used_size_ = arr.used_size_;
86+
self_allocated_ = arr.self_allocated_;
87+
allocated_size_ = arr.allocated_size_;
8788

88-
arr.reset();
89+
arr.reset();
90+
}
8991
return *this;
9092
}
9193

0 commit comments

Comments
 (0)