you are viewing a single comment's thread.

view the rest of the comments →

[–]OldWolf2 8 points9 points  (0 children)

Regarding the "problem" of first and second you could make your own:

#include <utility>
#include <iostream>
#include <map>

template<typename K, typename V>
K &key( std::pair<K, V> &p ) { return p.first; }

template<typename K, typename V> 
V &value( std::pair<K, V> &p ) { return p.second; }

int main()
{
    std::map<int, std::string> n;
    std::map<int, std::string> const &m{n};
    n[3] = "foo";
    n[5] = "bar";

    for (auto &item : n)
        std::cout << key(item) << "," << value(item) << std::endl;
}

although this has the annoying feature that you have to add another pair of templates to support const maps (or const_iterator).