Boost logo

Boost :

From: Gary Powell (Gary.Powell_at_[hidden])
Date: 2001-06-19 16:31:31


> [John Max Skaller]
> Let T be a tuple type.
> What is the name of the type of the n'th element?
>
> [Gary]
> It's not address' able by name per se. Instead use either the access
> function or the member function to get the nth item.

> [John Max Skaller]
        You misunderstood. What is the name of the TYPE of the n'th element?
If I have a tuple:

        tuple<T1,T2>

then the name of the TYPE of the first element is T1. How do I get the
name,
given only the tuple type?

This may be useful in some circumstances. For example:

        template<class T> void f(T t)(
                typename T::type1 x = get<1>(t);
                typename T::type2 y = get<2>(t);
        }

There is no use being able to get the n'th element,
if you can't name its type. Often, you know, but it would
be useful to get the type in a template where the tuple is
passed as a single T.

[Gary]
Sorry if I misunderstood. I think what you want was covered in Jaakko's
earlier email.

[Jaakko Jarvi]
> Let T be a tuple type.
> What is the name of the type of the n'th element?
element_type<N, T>::type gives you this.

[Gary]
So in your example it would be:

        template<class T> void f(T t)(
                typename boost::tuples::element_type<1, T>::type x =
get<1>(t);
                typename boost::tuples::element_type<2, T>::type y =
get<2>(t);
        }

Is this what you were looking for?

  Yours,
 -gary-

gary.powell_at_[hidden]


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