0

I know that std::map is by nature an ordered map, but I wonder:

If I have classes A and B and I create a std::map<A, B> myMap;, what is the minimal needed to create my own order?

Is overloading A::operator <(const A&) enough?

Or do I have to make my own iterator?

Benjamin Barrois
  • 2,566
  • 13
  • 30
  • Elements are sorted strictly by their keys. The value of `myMap[a1]` doesn't come into play at all. Maybe you want a `std::set` of your own pair type, which you can then sort whichever way you want taking both elements into consideration. – François Andrieux Aug 20 '18 at 17:31
  • @FrançoisAndrieux Yes there is a problem in what I wrote. I'm editing. – Benjamin Barrois Aug 20 '18 at 17:33
  • yes, you just have to write the operator < for class A. Class B is just supplying content and does not take part in the comparison. – Gem Taylor Aug 20 '18 at 18:13

0 Answers0