mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 01:55:07 +00:00
AK: Make HashTable::operator=(HashTable&&) clear the moved-from table
This is consistent with how other AK containers behave when moved from.
This commit is contained in:
parent
259822493f
commit
c584421592
|
@ -110,7 +110,8 @@ public:
|
|||
|
||||
HashTable& operator=(HashTable&& other) noexcept
|
||||
{
|
||||
swap(*this, other);
|
||||
HashTable temporary { move(other) };
|
||||
swap(*this, temporary);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,31 @@ TEST_CASE(construct)
|
|||
EXPECT_EQ(IntTable().size(), 0u);
|
||||
}
|
||||
|
||||
TEST_CASE(basic_move)
|
||||
{
|
||||
HashTable<int> foo;
|
||||
foo.set(1);
|
||||
EXPECT_EQ(foo.size(), 1u);
|
||||
auto bar = move(foo);
|
||||
EXPECT_EQ(bar.size(), 1u);
|
||||
EXPECT_EQ(foo.size(), 0u);
|
||||
foo = move(bar);
|
||||
EXPECT_EQ(bar.size(), 0u);
|
||||
EXPECT_EQ(foo.size(), 1u);
|
||||
}
|
||||
|
||||
TEST_CASE(move_is_not_swap)
|
||||
{
|
||||
HashTable<int> foo;
|
||||
foo.set(1);
|
||||
HashTable<int> bar;
|
||||
bar.set(2);
|
||||
foo = move(bar);
|
||||
EXPECT(foo.contains(2));
|
||||
EXPECT(!bar.contains(1));
|
||||
EXPECT_EQ(bar.size(), 0u);
|
||||
}
|
||||
|
||||
TEST_CASE(populate)
|
||||
{
|
||||
HashTable<String> strings;
|
||||
|
|
Loading…
Reference in a new issue