Skip to content

Commit

Permalink
Implement vector move assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
mtvec committed Aug 27, 2017
1 parent 2ce6fd6 commit f1d8762
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class vector
return *this;
}

// TODO Add noexcept
vector& operator=(vector&& other)
{
swap(other);
return *this;
}

size_type size() const noexcept
{
return size_;
Expand Down
11 changes: 11 additions & 0 deletions test/vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ TEST(a_vector, has_the_same_elements_as_the_source_vector_it_was_assigned_from)
ASSERT_THAT(vec, ElementsAreArray(source_vec));
}

TEST(a_vector, has_the_same_elements_as_the_source_vector_it_was_move_assigned_from)
{
auto source_vec = sut::vector(some_initializer_list);
auto source_copy = source_vec;

decltype(source_vec) vec;
vec = std::move(source_vec);

ASSERT_THAT(vec, ElementsAreArray(source_copy));
}

TEST(a_vector, has_the_same_elements_as_the_other_vector_after_swap)
{
auto vec1 = some_vec1;
Expand Down

0 comments on commit f1d8762

Please sign in to comment.