From: Weapon Liu (weapon.liu_at_[hidden])
Date: 2006-12-14 09:15:16
John Maddock wrote:
> I have a piece of boilerplate code that accepts a tuple (of any size) and
> prints out either a csv file or a boost::array C++ code conaining the data
> It allows me to output data for graphing, or matrixes of test data very
> quickly just by creating a short function that returns a tuple, and then
> passing that function to my boilerplate. If I want more columns of data I
> just increase the size of tuple by 1.
> I suppose I could have used a vector instead, but it's less elegant somehow.
> 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. Had I felt the need, I could have performed compile time
> dispatch to different algorithms based on how many derivatives were
> available (the tuples size).
Thanks John, that's very informative. Although a little bit of code
would be excellent :-)
I do have a question about the second application, I mean, don't you
have to wait until runtime to know how many derivatives a function
actually have? Or is it just that it can be known in the very scenario
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk