1
0
Fork 0

Codechange: move operator== inside MultiMap class and leave out ones that will be synthesized

pull/13494/head
Rubidium 2025-02-08 00:09:20 +01:00 committed by rubidium42
parent 5f41bc0279
commit 8fbba84473
1 changed files with 31 additions and 87 deletions

View File

@ -181,10 +181,6 @@ public:
this->operator--(); this->operator--();
return tmp; return tmp;
} }
};
/* Generic comparison functions for const/non-const MultiMap iterators and map iterators */
/** /**
* Compare two MultiMap iterators. Iterators are equal if * Compare two MultiMap iterators. Iterators are equal if
* 1. Their map iterators are equal. * 1. Their map iterators are equal.
@ -192,83 +188,31 @@ public:
* 3. If list_valid they agree about list_iter. * 3. If list_valid they agree about list_iter.
* Lots of template parameters to make all possible const and non-const types of MultiMap iterators * Lots of template parameters to make all possible const and non-const types of MultiMap iterators
* (on maps with const and non-const values) comparable to each other. * (on maps with const and non-const values) comparable to each other.
* @param iter1 First iterator to compare. * @param other Other iterator to compare to.
* @param iter2 Second iterator to compare. * @return If other is equal to this.
* @return If iter1 and iter2 are equal.
*/ */
template <class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tlist_iter2, class Tkey, class Tvalue1, class Tvalue2, class Tcompare> template <class Tmap_iter_other, class Tlist_iter_other, class Tvalue_other>
bool operator==(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare> &iter1, const MultiMapIterator<Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare> &iter2) bool operator==(const MultiMapIterator<Tmap_iter_other, Tlist_iter_other, Tkey, Tvalue_other, Tcompare> &other) const
{ {
if (iter1.GetMapIter() != iter2.GetMapIter()) return false; if (this->GetMapIter() != other.GetMapIter()) return false;
if (!iter1.ListValid()) return !iter2.ListValid(); if (!this->ListValid()) return !other.ListValid();
return iter2.ListValid() ? return other.ListValid() ?
iter1.GetListIter() == iter2.GetListIter() : false; this->GetListIter() == other.GetListIter() : false;
}
/**
* Inverse of operator==().
* Lots of template parameters to make all possible const and non-const types of MultiMap iterators
* (on maps with const and non-const values) comparable to each other.
* @param iter1 First iterator to compare.
* @param iter2 Second iterator to compare.
* @return If iter1 and iter2 are not equal.
*/
template <class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tlist_iter2, class Tkey, class Tvalue1, class Tvalue2, class Tcompare>
bool operator!=(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare> &iter1, const MultiMapIterator<Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare> &iter2)
{
return !(iter1 == iter2);
} }
/** /**
* Check if a MultiMap iterator is at the begin of a list pointed to by the given map iterator. * Check if a MultiMap iterator is at the begin of a list pointed to by the given map iterator.
* Lots of template parameters to make all possible const and non-const types of MultiMap iterators * Lots of template parameters to make all possible const and non-const types of MultiMap iterators
* (on maps with const and non-const values) comparable to all possible types of map iterators. * (on maps with const and non-const values) comparable to all possible types of map iterators.
* @param iter1 MultiMap iterator. * @param iter Map iterator.
* @param iter2 Map iterator. * @return If this points to the begin of the list pointed to by iter.
* @return If iter1 points to the begin of the list pointed to by iter2.
*/ */
template <class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcompare > template <class Titer>
bool operator==(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcompare> &iter1, const Tmap_iter2 &iter2) bool operator==(const Titer &iter) const
{ {
return !iter1.ListValid() && iter1.GetMapIter() == iter2; return !this->ListValid() && this->GetMapIter() == iter;
} }
};
/**
* Inverse of operator==() with same signature.
* @param iter1 MultiMap iterator.
* @param iter2 Map iterator.
* @return If iter1 doesn't point to the begin of the list pointed to by iter2.
*/
template <class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcompare >
bool operator!=(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcompare> &iter1, const Tmap_iter2 &iter2)
{
return iter1.ListValid() || iter1.GetMapIter() != iter2;
}
/**
* Same as operator==() with reversed order of arguments.
* @param iter2 Map iterator.
* @param iter1 MultiMap iterator.
* @return If iter1 points to the begin of the list pointed to by iter2.
*/
template <class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcompare >
bool operator==(const Tmap_iter2 &iter2, const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcompare> &iter1)
{
return !iter1.ListValid() && iter1.GetMapIter() == iter2;
}
/**
* Same as operator!=() with reversed order of arguments.
* @param iter2 Map iterator.
* @param iter1 MultiMap iterator.
* @return If iter1 doesn't point to the begin of the list pointed to by iter2.
*/
template <class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcompare >
bool operator!=(const Tmap_iter2 &iter2, const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcompare> &iter1)
{
return iter1.ListValid() || iter1.GetMapIter() != iter2;
}
/** /**
* Hand-rolled multimap as map of lists. Behaves mostly like a list, but is sorted * Hand-rolled multimap as map of lists. Behaves mostly like a list, but is sorted