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
    Posts
    2,598

    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.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,786
    Are you looking for something similiar to Boost.Bimap?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    Posts
    2,598
    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?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,786
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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