Skip to main content
GameDev.net gamedev.net
🔒 Locked

std::vector as key in std::map?

Started by Calexus Jul 6, 2011 at 12:49 PM 2 replies 1.5k views
Original Post
Calexus
Calexus
I'm in the process of debugging a rather massive system and I keep getting back to a part of the code that makes heavy use of std::map, std::long >, the code itself compiles perfectly well and for what I hear it has been working fine for years.

But still... is it really legal to use an std::vector as a key? I have never seen anyone use it before but I guess its legal as long as all the needed operators are provided.




Edit >> Sry forgot to say this is C++.


Exitus Acta Probat
alvaro
alvaro
You have to make sure you provide an operator< that is a strict weak ordering. The lexicographical order, for instance, should work.
Antheus
Antheus

Edit >> Sry forgot to say this is C++.


Technically, this is madness.
SiCrane
SiCrane

You have to make sure you provide an operator< that is a strict weak ordering. The lexicographical order, for instance, should work.

All standard library containers provide operator< by default that is implemented in terms of std::lexicographical_compare(). You don't need to supply it yourself.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.