Boost logo

Boost :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2006-12-14 09:52:04


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( ... );

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk