std::multimap & std::find()
-
Hello, lets take a look at the STL. We have
std::multimap pairs; void remove(sth* s1, sth* s2) { std::multimap::iterator i; if ((i = std::find(pairs.lower_bound(s1), pairs.upper_bound(s1), std::make_pair(s1, s2))) != pairs.end()) pairs.erase(i); }
Well that doesn't work. I get MANY template compile errors (really hard to read, and rearly make any sense). I'll give you a small sample:f:\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(31): error C2784: 'bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'std::allocator<_Ty>::value_type' with [ _Ty=std::pair ] f:\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(31): error C2784: 'bool std::operator ==(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'std::allocator<_Ty>::value_type' with [ _Ty=std::pair ] f:\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(31): error C2784: 'bool std::operator ==(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'std::allocator<_Ty>::value_type' with [ _Ty=std::pair ]
I think you get the idea. All the compile errors point inside std::find() where the arrow points:template inline _InIt find(_InIt _First, _InIt _Last, const _Ty& _Val) { // find first matching _Val for (; _First != _Last; ++_First) ----> if (*_First == _Val) break; return (_First); }
I just can't understand where the problem is. Everythink looks fine to me, but obviously it isn't. Anyother idea how am I supposed to erase a single pair from a std::multimap()? I can only find functions that erase all pairs for a specified key but I just need to erase one of those pairs given a specified mapped_value. That all, Themis PS - std::remove() also doesn't work as it relies on std::find() (at least in VS .NET 2003 implementation) -- modified at 6:08 Friday 23rd September, 2005 PS2 - I don't know if you are already aware of that but the code tags of the forum are not rendered properly with the Firefox Brows -
Hello, lets take a look at the STL. We have
std::multimap pairs; void remove(sth* s1, sth* s2) { std::multimap::iterator i; if ((i = std::find(pairs.lower_bound(s1), pairs.upper_bound(s1), std::make_pair(s1, s2))) != pairs.end()) pairs.erase(i); }
Well that doesn't work. I get MANY template compile errors (really hard to read, and rearly make any sense). I'll give you a small sample:f:\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(31): error C2784: 'bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'std::allocator<_Ty>::value_type' with [ _Ty=std::pair ] f:\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(31): error C2784: 'bool std::operator ==(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'std::allocator<_Ty>::value_type' with [ _Ty=std::pair ] f:\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(31): error C2784: 'bool std::operator ==(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'std::allocator<_Ty>::value_type' with [ _Ty=std::pair ]
I think you get the idea. All the compile errors point inside std::find() where the arrow points:template inline _InIt find(_InIt _First, _InIt _Last, const _Ty& _Val) { // find first matching _Val for (; _First != _Last; ++_First) ----> if (*_First == _Val) break; return (_First); }
I just can't understand where the problem is. Everythink looks fine to me, but obviously it isn't. Anyother idea how am I supposed to erase a single pair from a std::multimap()? I can only find functions that erase all pairs for a specified key but I just need to erase one of those pairs given a specified mapped_value. That all, Themis PS - std::remove() also doesn't work as it relies on std::find() (at least in VS .NET 2003 implementation) -- modified at 6:08 Friday 23rd September, 2005 PS2 - I don't know if you are already aware of that but the code tags of the forum are not rendered properly with the Firefox BrowsThemis wrote: PS2 - I don't know if you are already aware of that but the code tags of the forum are not rendered properly with the Firefox Browser. I haven't noticed anything wrong with the code tags. Are you sure your HTML is correct? :)
-
Themis wrote: PS2 - I don't know if you are already aware of that but the code tags of the forum are not rendered properly with the Firefox Browser. I haven't noticed anything wrong with the code tags. Are you sure your HTML is correct? :)
Yes I just read my message in firefox (browser I use) and then reloaded it in IE (just because of curiosity) and saw that in IE code blocks are printed red and the rest black. However in firefox everything is printed in black until a code block begins, then everything below that point prints in red, even after the code block end. Anyway that just a note. Themis