Re: map with pair as key
I am sorry, I tried so many things that I mixed up some code-parts...
That is why the hash-element is still in there. The overall goal was to
use a hash-map because I thought that it is more efficient (than the
tree-map in the standart implementation).
Did I understand it right that the following should work:
struct PairCompare
{
bool operator () (pair<int,int>* pp1, pair<int,int>* pp2) const
{
return pp1->first < pp2->first ||
pp1->first == pp2->first && pp1->second < pp2->second;
}
};
std::map<std::pair<std::pair<int,int>,int>, some_value_type> ?
Now, I have a question to the latter element: Why should this not work:
std::map<std::pair<int,int>, some_value_type, PairLess > ??
At last:
1. Why do you have a pointer to pair as key? A value would do it.
Otherwise your functor would be called with pointers.
--> This is as well a try-version error from me..Normally, I use
values!
2. The compare functor should be the 3rd template parameter.
--> see above.. thanks for the tip. I found my version in a tutorial
(using hash_map)..Could it be that the hash_map.h needs the
equal-operator as fourth parameter?
3. What is hash<> and why do you use it here?
--> I wanted to use hash_map instead of map. This is why it was still
here.
4. "Unforunately, this does not work." does not help us. Copy&Paste the
error messages. Say, *what* went wrong, not *that* something went
wrong.
--> I got the most different error-messages one could imagine. Since I
changed the code from char* to pair as keys, I ot about 100 compiling
errors...
Again, thanks a lot for your help.
If the map is instantiated, would I add elements by using
pair<int,int> p (3,2);
connections[p]=3.3;
??
Thanks a lot once more..