Ben Hutchings wrote:
Jim Lear wrote:
The map iterators are really what tripped me up as an STL newbie. One must understand the iterators are implemented as pairs for maps, and pointers for vectors and other things. By providing an "T operator[](iterator)" function for random access and associative containers (and for sequences maybe), one could achieve a consistant interface.
Container-independent code is an impossible and pointless goal. maps have different semantics from other containers. You may want to iterate over just the mapped values, but other people may want to iterate over the keys, or over the pairs (and indeed, so may you, in other part of your program). Who's to say which of these is right? What you can do is to write iterator-independent code, then use an iterator adapter to convert the iterators over pairs into iterators over the mapped values:
Have you seen http://www.zib.de/weiser/vtl/ and http://www.boost.org/libs/range/index.html? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com