1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
template <typename Key, typename T, typename KeyEqual, typename Hash>
void hash_map<Key, T, KeyEqual, Hash>::swap(
hash_map<Key, T, KeyEqual, Hash>& other) noexcept
{
using std::swap;
swap(mBuckets, other.mBuckets);
swap(mSize, other.mSize);
swap(mEqual, other.mEqual);
swap(mHash, other.mHash);
}
//The following swap function just forwards to the previous member function:
template <typename Key, typename T, typename KeyEqual, typename Hash>
void swap(hash_map<Key, T, KeyEqual, Hash>& first,
hash_map<Key, T, KeyEqual, Hash>& second)
{
first.swap(second);
}
//Assignment operators
template <typename Key, typename T, typename KeyEqual, typename Hash>
hash_map<Key, T, KeyEqual, Hash>&
hash_map<Key, T, KeyEqual, Hash>::operator=(
const hash_map<Key, T, KeyEqual, Hash>& rhs)
{
if (this == &rhs) return *this;
auto copy = rhs;
swap(copy);
return *this;
}
//Move assignment
template <typename Key, typename T, typename KeyEqual, typename Hash>
hash_map<Key, T, KeyEqual, Hash>&
hash_map<Key, T, KeyEqual, Hash>::operator=(
const hash_map<Key, T, KeyEqual, Hash>&& rhs) noexcept
{
swap(rhs);
return *this;
}
| |