Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-04-18 10:20:06


----- Original Message -----
From: "Andrei Alexandrescu" <andrewalex_at_[hidden]>

> "David Abrahams" <david.abrahams_at_[hidden]> wrote in message
> news:005e01c1e68c$871cb520$6501a8c0_at_boostconsulting.com...
> > One very simple example of why you'd want to work with a different
> type
> > sequence (and this doesn't even speak to differences in structure)
> is
> > that you might want to operate on the sequence of types held by a
> > boost::tuple. One ought to be able to re-use the metaprogramming
> library
> > for that purpose.
>
> One could use dot-typelists to represent tuple's compound type, right?
> That's what Loki does in its very embrionary Tuple class.

Let's just assume we're working only with dot-typelist-like structures
for the time being. It's fairly easy to abstract out the head, tail,
etc.

template <class T> struct head;
template <class T,class U> struct head<tuple_node<T,U> > {
    typedef T type;
};

template <class T,class U> struct head<list_node<T,U> > {
    typedef T type;
};

other formulations possible; you get the idea. IMO, this small amount of
abstraction is worth it if you have enough useful algorithms which can
exploit it. I'd rather write out a couple of simple traits classes so
that I could easily manipulate tuples with MPL, than write a
tuple->typelist translator. Why? I'm not sure I can justify it on other
than aesthetic grounds.

-Dave


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