Finding the type of a pointed to element

  • Thread starter Adam H. Peterson
  • Start date
A

Adam H. Peterson

I have a type T (in a template) which I know (or assume) is a pointer to
a pair type. I would like to find out what the type of the second
element in the pair is. If T were simply a pair, I could get this by
doing something like:

typedef typename T::second_type U;

But how do I handle when T is a _pointer_to_ a pair type (or actually an
iterator type for a pointer to some pair type)?

Thanks in advance,
Adam Peterson
 
D

David Harmon

On Tue, 06 Apr 2004 15:53:02 -0600 in comp.lang.c++, "Adam H. Peterson"
I have a type T (in a template) which I know (or assume) is a pointer to
a pair type. I would like to find out what the type of the second
element in the pair is. If T were simply a pair, I could get this by
doing something like:

typedef typename T::second_type U;

If your compiler has good support for template partial specialization I
think you should be able to use

typedef typename std::iterator_traits<T>::value_type::second_type U;
 
A

Adam H. Peterson

David said:
On Tue, 06 Apr 2004 15:53:02 -0600 in comp.lang.c++, "Adam H. Peterson"



If your compiler has good support for template partial specialization I
think you should be able to use

typedef typename std::iterator_traits<T>::value_type::second_type U;

g++ 3.2.2 20030222

Bravo. Thanks, it appears to work.

Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top