|
Boost : |
From: Joel de Guzman (joel_at_[hidden])
Date: 2006-12-14 17:49:45
Thorsten Ottosen wrote:
> John Maddock wrote:
>> Weapon Liu wrote:
>>
>>> I personally very like this fancy facility, and that's why I present
>>> these mumbles here to annoy you guys( if so, my apologies go here:-))
>>> Any comments?
>>
>> I can give you one use I have for tuples:
>
>> I've also used tuples in place of struct's whenever I have an API that needs
>> to return more than 2 items. For example I have some root finding
>> algorithms that accept a unary functor whose root is to be found: the
>> functor returns a tuple containing the function evaluation, plus the first
>> two derivatives. Using a tuple here simplified both implementation and
>> documentation.
>
> I have used tuples in a similar manner, but I kinda think its not the
> best to do; a named tuple would be more appropriate, or maybe just a struct.
>
> What bothers me is the self-explanatory properties are lost; I can't
> figure out what tuple element that means what by just looking at the
> code. Is it
>
> tie(eval,dev1,dev2) = find_root(...)
>
> or
>
> tie(dev1,dev2,eval) = find_root(...)
>
> ?
>
> Instead a struct would be somewhat unambiguous:
>
> template< class Float >
> struct root_result
> {
> Float eval, dev1, dev2;
> };
>
> root_result<float> r = find_root( ... );
You can probably use a fusion map if you want the elements named.
Regards,
-- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk