[try Beta version]
Not logged in

 
Limits to Map Key

Jun 19, 2013 at 6:29am
What are the requirements for the type of the key of a std::map?

On this page (http://www.cplusplus.com/reference/map/map/), I noticed that the key type has to enforce a strict ordering (which I interpret to mean implementing operator<). Is this the only requirement for the type of the key?
Jun 19, 2013 at 7:06am
> Is this the only requirement for the type of the key?

Yes. Other than the obvious requirements of being CopyAssignable and Destructible.
Jun 19, 2013 at 11:07am
Strict weak ordering means that operator< should behave in a certain way. If a < b and b < c then you should also have that a < c. a < a should always return false. By testing if a < b and b < a both returns false is how they can know that a and b are equal.
Topic archived. No new replies allowed.