unordered_multimap - Iteration das Ergebnis von find() liefert Elemente mit unterschiedlichen Wert

Die multimap in C++ zu funktionieren scheint wirklich seltsam, ich würde gerne wissen, warum

#include <iostream>
#include <unordered_map>

using namespace std;

typedef unordered_multimap<char,int> MyMap;

int main(int argc, char **argv)
{
    MyMap map;
    map.insert(MyMap::value_type('a', 1));
    map.insert(MyMap::value_type('b', 2));
    map.insert(MyMap::value_type('c', 3));
    map.insert(MyMap::value_type('d', 4));
    map.insert(MyMap::value_type('a', 7));
    map.insert(MyMap::value_type('b', 18));

    for(auto it = map.begin(); it != map.end(); it++) {
        cout << it->first << '\t';
        cout << it->second << endl;
    }

    cout << "all values to a" << endl;
    for(auto it = map.find('a'); it != map.end(); it++) {
        cout << it->first << '\t' << it->second << endl;
    }

}

dies ist die Ausgabe:

c   3
d   4
a   1
a   7
b   2
b   18
all values to a
a   1
a   7
b   2
b   18

warum nimmt der Ausgang immer noch alles enthalten, mit b als Schlüssel, wenn ich explizit gefragt, für 'einen'? Ist das ein compiler-oder stl-bug?

InformationsquelleAutor Arne | 2012-01-28

Schreibe einen Kommentar