<, == and != done
This commit is contained in:
parent
09d2323cbf
commit
9271042e78
1 changed files with 33 additions and 3 deletions
36
Map.hpp
36
Map.hpp
|
@ -940,9 +940,39 @@ public:
|
||||||
}
|
}
|
||||||
void erase(const Key_T &key) { this->erase(this->find(key)); }
|
void erase(const Key_T &key) { this->erase(this->find(key)); }
|
||||||
// TODO:
|
// TODO:
|
||||||
friend bool operator==(const Map &lhs, const Map &rhs) { assert(false); }
|
friend bool operator==(const Map &lhs, const Map &rhs) {
|
||||||
friend bool operator!=(const Map &lhs, const Map &rhs) { assert(false); }
|
if (lhs.size() != rhs.size()) {
|
||||||
friend bool operator<(const Map &lhs, const Map &rhs) { assert(false); }
|
return false;
|
||||||
|
}
|
||||||
|
auto lhs_iter = lhs.begin();
|
||||||
|
auto rhs_iter = rhs.begin();
|
||||||
|
while (lhs_iter != lhs.end()) {
|
||||||
|
if (*lhs_iter != *rhs_iter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
++lhs_iter;
|
||||||
|
++rhs_iter;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
friend bool operator!=(const Map &lhs, const Map &rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
friend bool operator<(const Map &lhs, const Map &rhs) {
|
||||||
|
auto lhs_iter = lhs.begin();
|
||||||
|
auto rhs_iter = rhs.begin();
|
||||||
|
while (lhs_iter != lhs.end() && rhs_iter != rhs.end()) {
|
||||||
|
if (*lhs_iter < *rhs_iter) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (*lhs_iter != *rhs_iter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
++lhs_iter;
|
||||||
|
++rhs_iter;
|
||||||
|
}
|
||||||
|
return lhs.size() < rhs.size();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} // namespace cs440
|
} // namespace cs440
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue