[tuple] How to manipulate the types

Problem:
How can I get a tuple type from a tuples::cons<> list ?
example:
given the type:
cons

Adrián Etchevarne ha escrito:
Problem: How can I get a tuple type from a tuples::cons<> list ? example: given the type: cons
> > obtain tuple
Real problem: I need to insert a type T at the beginning of a tuple, how I can do this?
example given the type T and tuple
, obtain a tuple Thanks in advance, Adrián
Hi Adrián, I think you've got to resort to brute force, although Boost.PP helps a lot with this kind of tasks. Please find attached a possible implementation of a tuple_from_cons helper metafunction, though I'm sure the PP experts out there could come out with simpler and nicer formulations. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo ___________________________________________________________________________ Antes de imprimir este mensaje, asegúrese de que es necesario. La mejora del medio ambiente empieza en nuestro día a día. ___________________________________________________________________________

Adrián Etchevarne
Problem:
How can I get a tuple type from a tuples::cons<> list ?
example:
given the type:
cons
> >
obtain
tuple
Real problem:
I need to insert a type T at the beginning of a tuple, how I can do this?
example
given the type T and tuple
, obtain a tuple
That's a lot easier to solve, in some sense, than the "Problem:"
above. The cons list *is* a valid tuple. So to inserta new type at
the front, just write
const

David Abrahams wrote:
You might also want to look at
http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/index.h...
which was recently accepted into Boost.
Has the final decision been announced somewhere? João

João Abecasis wrote:
David Abrahams wrote:
You might also want to look at
http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/index.h...
which was recently accepted into Boost.
Has the final decision been announced somewhere?
AFAIK, not yet. I think Ronald Garcia is in vacation somehere :) Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

David Abrahams wrote:
That's a lot easier to solve, in some sense, than the "Problem:"
above. The cons list *is* a valid tuple. So to inserta new type at
the front, just write
const
Thanks to David and Joaquín for their response.
tuple inherit from cons, so tuple is a cons.
cons<> has an implicit conversion to tuple, but the types are not the same
(or I am missing something):
template< typename Cons, typename T>
struct p_front
{
typedef cons
You might also want to look at
http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/index.h...
which was recently accepted into Boost.
I will read it, thanks. It looks great! Thanks, Adrián

David Abrahams wrote:
That's a lot easier to solve, in some sense, than the "Problem:"
above. The cons list is a valid tuple. So to inserta new type at
the front, just write
const
Thanks to all for your responses.
tuple inherit from cons, so tuple is a cons.
cons<> has an implicit conversion to tuple, but the types are not the same
(or I am missing something):
template< typename Cons, typename T>
struct p_front
{
typedef cons
You might also want to look at
http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/index.h...
which was recently accepted into Boost.
I will read it, thanks. It looks great! Thanks, Adrián

I needed to do exactly this myself. My solution is attached. After
including this header, if you have an existing tuple type T, you can do
what you want with
typedef boost::tuples::add_type
Problem: How can I get a tuple type from a tuples::cons<> list ? example: given the type: cons
> > obtain tuple
Real problem: I need to insert a type T at the beginning of a tuple, how I can do this?
# pragma once
# include
participants (7)
-
Adrián Etchevarne
-
Adrián Etchevarne
-
Alan M. Carroll
-
David Abrahams
-
Joaquín Mª López Muñoz
-
Joel de Guzman
-
João Abecasis