Boost logo

Boost Users :

Subject: Re: [Boost-users] [Tuple] What's the point?
From: Neil Groves (neil_at_[hidden])
Date: 2009-07-10 06:23:16


On Fri, Jul 10, 2009 at 11:06 AM, Vladimir Prus
<vladimir_at_[hidden]>wrote:

> Robert Jones wrote:
>
> > I know that sounds like a slightly flippant question, but I really don't
> get
> > it.
> >
> > I've used tuples a few times, always for the multiple return value
> behaviour
> > using tie( ), but
> > in the end it always seems to be a better solution to use a struct. Code
> > like
> >
> > t.get<1>( ) = "fred";
> >
> > is a bit non-obvious, compared to
> >
> > t.forename = "fred";
> >
> > So have I entirely missed the point of tuples?
>

I think your point is valid, and often a structure will be preferable.
However there are examples that are killer cases for tuple. My favourite is
when combining functors. It is possible to use a tuple of functors that uses
the generic for_each mechanism to provide superb maintainable composition,
allowing lightweight orthogonally separated pieces of functionality that are
when composed suffer zero performance overhead. I have to stop... because
I'm getting excited! I can send some examples to the list or to you (Robert)
if desired.

>
> FWIW, I've stopped using tuples because using indices as opposed to names
> turned
> out to a maintenance nightmare.
>

Often this is true, but it's a magnificent tools when it is appropriate.

>
> - Volodya
>
> Regards,
Neil Groves



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net