Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > iterator_traits

Reply
Thread Tools

iterator_traits

 
 
Lieven
Guest
Posts: n/a
 
      12-02-2004
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 ?

 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      12-02-2004
Lieven wrote in news:41af1926$0$25065$ 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.
--
http://www.victim-prime.dsl.pipex.com/
 
Reply With Quote
 
 
 
 
Jonathan Turkanis
Guest
Posts: n/a
 
      12-02-2004

"Lieven" <> wrote in message
news:41af1926$0$25065$...
> 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


 
Reply With Quote
 
Siemel Naran
Guest
Posts: n/a
 
      12-03-2004
"Rob Williscroft" <> wrote in message
> Lieven wrote in news:41af1926$0$25065$ 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>.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
template<class Type> struct iterator_traits<const Type*> Taras_96 C++ 0 04-01-2008 07:13 AM
iterator_traits::value_type on back_insert_iterator - returns void anto.anish@gmail.com C++ 14 02-12-2008 11:14 AM
typename iterator_traits::pointer Ioannis Vranos C++ 10 01-25-2008 12:25 AM
help on std::iterator_traits? Jess C++ 3 06-28-2007 03:01 PM
Purpose of iterator_traits::value_type chris C++ 8 12-10-2004 04:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57