I have a map as follows:
std::map<A, long> myMap
The ordering of this map is important so I am trying to figure out how the map will be ordered. I have found that on the documentation of this class it says Internally, the elements in the map are sorted from lower to higher key value following a specific strict weak ordering criterion set on construction but I don’t understand what this means. Will it call the ‘<‘ operator on the two objects to figure out the ordering?
I am also aware that I could just pass the map a struct as follows on initialisation and it will do as I want. I am just curious as to what it does by default.
struct classcomp {
bool operator() (const A& lhs, const A& rhs) const
{return lhs<rhs;}
};
Yes, it will:
Make sure that the “less than” relation defined by your
operator<is transitive, i.e. ifA < BandB < C, thenAmust be less thanCas well.