I was wondering if there was anything in the c++ std lib similar to the python dictionary. I know of maps/multimaps but from what I can tell it only allows for ONE mapping between a key/value pair. I need something that can keep separate tallies but also normalize them, like for example: {"red":4, "blue":10, "green":2} and then once normalized: {"red":0.25, "blue": 0.625, "green": 0.125}.
Now I'm trying to create a Counter class that mimics the python functionality by using multimaps. Right now it can just handle counters of the sort
In particular, I'm trying to write a function, increment_count(int key, double value), that does the following: if the key is not present in the mapping, add the pair (key,0) to the mapping. If it is present, then bump up the value by 1. I can do the latter, but I'm not sure exactly how I can write a conditional that checks if the key exists in the mapping. The function multimap::find seems to hold the answer, because it will make the iterator point to end if the key was not found, but then how would I get an if statement to check if the iterator is pointing to the end? Something like it (the iterator) == multimap::end doesn't seem to work.
@Althar , hey which compiler do I need to compile that code ? It certainly has some C++0x features I can see. Just curious, looks like a very fast and smart implementation.