@@ -197,6 +197,20 @@ public:
swap(key_equals_, other.key_equals_);
}
friend void swap(bucket_hash_map & lhs, bucket_hash_map & rhs) { lhs.swap(rhs); }
+ friend bool operator==(bucket_hash_map const & lhs, bucket_hash_map const & rhs) {
+ if (lhs.size() != rhs.size()) { return false; }
+ auto end = rhs.end();
+ for (auto & pair : lhs) {
+ auto it = rhs.find(pair.first);
+ if (it == end || it->second != pair.second) {
+ return false;
+ }
+ return true;
+ friend bool operator!=(bucket_hash_map const & lhs, bucket_hash_map const & rhs) {
+ return !(lhs == rhs);
private:
void maybe_expand(size_type add) {
if ( static_cast<float>(size() + add) / bucket_count() > max_load_factor() ) {
@@ -249,4 +249,10 @@ public:
TS_ASSERT(hm.empty());
+ void test_resize_not_destructive() {
+ hashmap hm{{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}};
+ hashmap const copy{hm};
+ hm.reserve(6);
+ TS_ASSERT_EQUALS(hm, copy);
};
@@ -219,6 +219,15 @@ private:
return { ::iterator::in_place, make_end_aware_iterator(b.current(), b.end()),
make_end_aware_iterator(b->erase(l.current()), l.end()) };
+private:
+ friend bool operator==(bucket_hash_set const & lhs, bucket_hash_set const & rhs) {
+ for (auto & val : lhs) { if (rhs.count(val) == 0) { return false; } }
+ friend bool operator!=(bucket_hash_set const & lhs, bucket_hash_set const & rhs) {
private: // members
impl_type buckets_{default_buckets};
hasher hasher_;
@@ -201,4 +201,10 @@ public:
+ hashset hm{0, 1, 2, 3, 4, 5};
+ hashset const copy{hm};