From: Joel de Guzman (joel_at_[hidden])
Date: 2007-10-04 07:52:44
Phil Endecott wrote:
> Simonson, Lucanus J wrote:
> * xyz or [n] notation: using .x, .y and .z to access the coordinates
> seems simpler to me, but the higher-dimension people would prefer to
> use ,  ... [n]. That notation also has the advantage that you
> can iterate through the dimensions. Is it possible to support both?
Yes! Use fusion to do the mapping, making all your structs, arrays or
whatnots, whatever they are, compatible. You deal with them in
a uniform manner. You don't care if the point type (for example)
is from library A or library B. It just works. Here's an example:
namespace A // library A
namespace B // library B
float y; // y comes first!
namespace C // library B
typedef boost::array<int, 2> Point;
Now, let's adapt these structs to make them tuples (boost::array
is already adapted without doing anything else):
Now, in your generic code, you simply refer to X and Y as:
get<1>(p); // x
get<2>(p); // y
regardless if p is a boost::array, a boost::tuple, a B::Point,
or an A::point. They are all compatible. And, the bonus is that
because they are now first class fusion sequences (A::point and
B::point), all fusion iterators and algorithms can be used.
Yes, you can iterate through all the dimensions!
-- 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