iterator_traits

L

Lieven

Is there a way in C++, given an iterator, I can get the container it's
pointing to, in analogy of anIterator::value_type which gives the type of
the elements of the container ?
 
R

Rob Williscroft

Lieven wrote in in
comp.lang.c++:
Is there a way in C++, given an iterator, I can get the container it's
pointing to, in analogy of anIterator::value_type which gives the type of
the elements of the container ?

No, sorry. There simply isn't enough information associated with
an iterator type to work back to the container.

As an example a T * type could be an iterator into an inbuilt array
T array[ 100 ] or a std::vector< T >.

Rob.
 
J

Jonathan Turkanis

Lieven said:
Is there a way in C++, given an iterator, I can get the container it's
pointing to, in analogy of anIterator::value_type which gives the type of
the elements of the container ?

You can't even get the type of container its pointing into, unless its one of
the standard inerter iterators.

Jonathan
 
S

Siemel Naran

Rob Williscroft said:
Lieven wrote in news:[email protected] in
Is there a way in C++, given an iterator, I can get the container it's
pointing to, in analogy of anIterator::value_type which gives the type of
the elements of the container ?

No, sorry. There simply isn't enough information associated with
an iterator type to work back to the container.

As an example a T * type could be an iterator into an inbuilt array
T array[ 100 ] or a std::vector< T >.

As far as standard containers go, it could also be a std::basic_string<int>.
 

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
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top