diff --git a/lib/glacier/container/hash_map.h b/lib/glacier/container/hash_map.h index 9d72b6f..10d4aca 100644 --- a/lib/glacier/container/hash_map.h +++ b/lib/glacier/container/hash_map.h @@ -18,9 +18,8 @@ class HashMap { HashMap() = default; HashMap(const HashMap&) = delete; HashMap& operator=(const HashMap&) = delete; - // TODO: Implement Move. - HashMap(HashMap&&) = delete; - HashMap& operator=(HashMap&&) = delete; + HashMap(HashMap&&); + HashMap& operator=(HashMap&&); // Accessors. uint64_t size() { return size_; } @@ -63,6 +62,21 @@ class HashMap { void ResizeIfNecessary(); }; +template +HashMap::HashMap(HashMap&& other) { + data_ = glcr::Move(other.data_); + size_ = other.size_; + other.size_ = 0; +} + +template +HashMap& HashMap::operator=(HashMap&& other) { + data_ = glcr::Move(other.data_); + size_ = other.size_; + other.size_ = 0; + return *this; +} + template V& HashMap::at(const K& key) { uint64_t hc = H()(key); @@ -74,7 +88,8 @@ V& HashMap::at(const K& key) { } } // TODO: Add a failure mode here instead of constructing an object. - ll.PushFront({key, {}}); + K k2 = key; + ll.PushFront({glcr::Move(k2), {}}); return ll.PeekFront().second(); }