Thread: Triple structure

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    197

    Triple structure

    Is there an structure to hold triples...
    i know we have stl pair to hold pairs...
    But i am in need of structure storing triples

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by dpp
    Is there an structure to hold triples...
    i know we have stl pair to hold pairs...
    But i am in need of structure storing triples
    You could consider Boost.Tuple.
    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
    Join Date
    Jan 2009
    Posts
    197
    Is there any other approach without using such boost libararies...

    I am not allowed to do that

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by dpp
    Is there any other approach without using such boost libararies...
    Define such a triple structure yourself.
    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

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    197
    yes i ll do that in the worst case
    But all i needed to know was whether there exist a similar one like "pair" or can a few combinations of someother structures would land up in triple...
    hope there is not

  6. #6
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    It's not complicated, just write your own
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    197
    yes it is easy...
    But all i wanted is triple in the priority queue
    Code:
     priority_queue<int,vector<int>, compare > pq;
    is the minimal one..,.

    I used pairs to hold doubles...
    Now i am running short of options to hold triples

  8. #8
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    Like everyone has said, create your own templated class and work from there.
    MSDN <- Programmers Haven!

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    How about
    Code:
    pair < T1, pair < T2, T3 > >
    ?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    Quote Originally Posted by matsp View Post
    How about
    Code:
    pair < T1, pair < T2, T3 > >
    ?
    Wow, I never thought of a pair inside a pair! Nice.
    MSDN <- Programmers Haven!

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The bad part about simulating a triple with a pair that contains a pair as the second object is that accessing the second and third objects would involve syntax such as x.second.first and x.second.second as opposed to x.second and x.third (or in the case of Boost.Tuple, x.get<1>() and x.get<2>()).
    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

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    The bad part about simulating a triple with a pair that contains a pair as the second object is that accessing the second and third objects would involve syntax such as x.second.first and x.second.second as opposed to x.second and x.third (or in the case of Boost.Tuple, x.get<1>() and x.get<2>()).
    Sure, it's not very nice. I'm not convinced the tuple solution is much nicer, really.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    Code:
    template<typename T1,typename T2,typename T3>triple
    {
    public:
        triple(const T1 &t1,const T2 &t2,const T3 &t3):
            first(t1),
            second(t2),
            third(t3)
        {
        }
        T1 first;
        T2 second;
        T3 third;
    };


    i'll leave it to you to figure out how to specialize (or de-optimize) if you want to store indirect types in your triple.

  14. #14
    Registered User
    Join Date
    Jan 2009
    Posts
    197
    But i successfully simulated using pairs... Infact i started to do with pairs and achieved what i wanted...
    When i got back to the forum ,I saw matsp has given exactly the method which i worked with...
    Not sure about its efficiency...But it was all needed for me
    Cheers Matsp
    Thanks evryone anyways
    Last edited by dpp; 06-25-2009 at 11:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  2. Replies: 5
    Last Post: 02-14-2006, 09:04 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM