Boost logo

Boost Users :

Subject: Re: [Boost-users] [Tuple] What's the point?
From: Joel de Guzman (joel_at_[hidden])
Date: 2009-07-10 06:36:56


Johan Nilsson wrote:
> 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.
>
> So, what's wrong with using named constants for the indices? That's what
> I've been most of the time when using tuples.

Named constants are fragile. If you add a member (say in the middle),
it breaks. You have to make sure they are in sync. Better use
associative tuples (e.g.):

     t.at_key<name>( ) = "fred";

But, IMO, that's not better than plain struct's:

     t.name = "fred";

I'd say:

* use structs with non-generic code.
* use tuples with generic code.
* use FUSION_ADAPT_STRUCT to bridge between the two.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

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