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

Printable View

- 06-23-2009dppTriple 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 - 06-23-2009laserlightQuote:

Originally Posted by**dpp**

- 06-23-2009dpp
Is there any other approach without using such boost libararies...

I am not allowed to do that - 06-23-2009laserlightQuote:

Originally Posted by**dpp**

- 06-23-2009dpp
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 - 06-23-2009ಠ_ಠ
It's not complicated, just write your own

- 06-23-2009dpp
yes it is easy...

But all i wanted is triple in the priority queue

Code:`priority_queue<int,vector<int>, compare > pq;`

I used pairs to hold doubles...

Now i am running short of options to hold triples - 06-23-2009legit
Like everyone has said, create your own templated class and work from there. :)

- 06-23-2009matsp
How about

Code:`pair < T1, pair < T2, T3 > >`

--

Mats - 06-23-2009legit
- 06-23-2009laserlight
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>()).

- 06-23-2009matsp
- 06-23-2009m37h0dCode:
`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. - 06-26-2009dpp
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