I have a paired key map named mymap and I have defined a comparison operator named cmplt_cmprsn shown below
#include <iostream>
#include <map>
struct prtl_cmprsn {
bool operator()(
const std::pair<int64_t, int64_t> &left,
const std::pair<int64_t, int64_t> &right) const
{
return left.first > right.first;
}
};
struct cmplt_cmprsn {
bool operator()(
const std::pair<int64_t, int64_t> &left,
const std::pair<int64_t, int64_t> &right) const
{
return left.first != right.first
? left.first > right.first
: left.second > right.second;
}
};
int main ()
{
std::map<std::pair<int64_t, int64_t>, double, cmplt_cmprsn> mymap;
return 0;
}
which provides a complete comparison between unique paired keys that are used in mymap.
I want to perform two separate iterations through mymap:
(1) iterate over all unique paired keys in one full iteration
(2) find all unique first sub-keys and iterate over unique paired keys sharing those first sub-keys in two nested iterations.
I can write a partial comparison operator named prtl_cmprsn shown above. However, mymap already has been defined using cmplt_cmprsn operator. Is there a way to switch comparison operators after the map is defined, or having multiple comparison operators is not possible in this context?