Tuesday, July 14, 2009

Index [] for map but not multimap, C++. ?

Why does C++ STL's map overload the operator [] but the multimap does not?

Index [] for map but not multimap, C++. ?
Because using [] would be undefined for a multi-map.





A multi-map allows for a one-to-many mapping while a map uses a one-to-one.





For a map you can use the [] operater for getting and retrieving values. But with a multi-map, you have more than one value for each key. So how would you define the [] operator in a way that would work for all cases?





There really isn't an elegant way to do it.





~X~


No comments:

Post a Comment