Reputation: 7101
I have an unordered_map:
std::tr1::unordered_map<unsigned int, vector<unsigned int> > duplicates;
Anad I would like to insert:
duplicates.insert(make_pair(1, 2));
duplicates.insert(make_pair(1, 5));
duplicates.insert(make_pair(1, 6));
into the vector because they share the same key. I use a for loop for inserting pairs. How can I initialise the vector if no items share the same key and it is the first time that I find that key without searching the whole unordered_map?
I do not want to first use find (to get the vector if exist) and then insert. Is that possible?
Upvotes: 0
Views: 1822
Reputation: 38576
Sorry if I misunderstood your question, but perhaps you might find use in something like unordered_multimap
?
Unordered multimaps are associative containers that store elements formed by the combination of a key value and a mapped value, much like
unordered_map
containers, but allowing different elements to have equivalent keys.
Upvotes: 1