How do I make a container where 'key' and 'value' are interchangeable ?

This is a discussion on How do I make a container where 'key' and 'value' are interchangeable ? within the C++ Programming forums, part of the General Programming Boards category; Suppose I have a set of 'pair' `s. How would I encapsulate it so that I can get an equal_range ...

  1. #1
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498

    How do I make a container where 'key' and 'value' are interchangeable ?

    Suppose I have a set of 'pair' `s.
    How would I encapsulate it so that I can get an equal_range w.r.t both 'first' and 'second', corresponding to the other; when necessary?

    I tried using multimap, but It seems to allow getting the range by keys only, not the other way around.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,409
    Are you looking for something similiar to Boost.Bimap?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by laserlight View Post
    Are you looking for something similiar to Boost.Bimap?
    Reading the 'One Minute Tutorial"... it seems to be what I need....almost.
    I couldn't find out from a glance if it allows multiple values per key w.r.t both left and right view.
    Does it?
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,409
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. interchangeable functions
    By megafiddle in forum General Discussions
    Replies: 13
    Last Post: 08-28-2011, 09:19 PM
  2. Looking for appropriate container
    By Elysia in forum C++ Programming
    Replies: 20
    Last Post: 07-27-2010, 04:51 PM
  3. Replies: 1
    Last Post: 01-23-2006, 06:12 PM
  4. Replies: 4
    Last Post: 03-21-2004, 02:34 PM
  5. I/O using a STL container
    By LA Mills in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2003, 12:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21