Boost logo

Boost Users :

Subject: Re: [Boost-users] [Tuple] What's the point?
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2009-07-10 08:33:36


Vladimir Prus 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?
>
> FWIW, I've stopped using tuples because using indices as opposed to names turned
> out to a maintenance nightmare.
>
> - Volodya

There are usages where you don't use any indices! My favorite is:

struct A
{
    int k;
    std::string n;
    double x;
    Other o;
};

bool operator<(A const& lhs, A const& rhs)
{
    return tie(lhs.k, lhs.n, lhs.x, lhs.o)
         < tie(rhs.k, rhs.n, rhs.x, rhs.o);
}

I'm sure Joel, could point out that this is done automatically with with
  the adapt struct macro.

Jeff


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