Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. std::multimap & std::find()

std::multimap & std::find()

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Themis
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • T Themis

      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

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      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? :)

      T 1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        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? :)

        T Offline
        T Offline
        Themis
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups