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
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.Originally Posted by dpp
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Is there any other approach without using such boost libararies...
I am not allowed to do that
Define such a triple structure yourself.Originally Posted by dpp
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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
It's not complicated, just write your own
╔╗╔══╦╗
║║║╔╗║║
║╚╣╚╝║╚╗
╚═╩══╩═╝
yes it is easy...
But all i wanted is triple in the priority queue
is the minimal one..,.Code:priority_queue<int,vector<int>, compare > pq;
I used pairs to hold doubles...
Now i am running short of options to hold triples
Like everyone has said, create your own templated class and work from there.
MSDN <- Programmers Haven!
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.
MSDN <- Programmers Haven!
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>()).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
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.