iterator_traits

Discussion in 'C++' started by Lieven, Dec 2, 2004.

  1. Lieven

    Lieven Guest

    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 ?
     
    Lieven, Dec 2, 2004
    #1
    1. Advertising

  2. 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/
     
    Rob Williscroft, Dec 2, 2004
    #2
    1. Advertising

  3. "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
     
    Jonathan Turkanis, Dec 2, 2004
    #3
  4. Lieven

    Siemel Naran Guest

    "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>.
     
    Siemel Naran, Dec 3, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chris
    Replies:
    8
    Views:
    500
    Tom Widmer
    Dec 10, 2004
  2. Jess
    Replies:
    3
    Views:
    654
    Zeppe
    Jun 28, 2007
  3. Ioannis Vranos

    typename iterator_traits::pointer

    Ioannis Vranos, Jan 24, 2008, in forum: C++
    Replies:
    10
    Views:
    713
    Ioannis Vranos
    Jan 25, 2008
  4. Replies:
    14
    Views:
    1,353
    Triple-DES
    Feb 12, 2008
  5. Taras_96
    Replies:
    0
    Views:
    380
    Taras_96
    Apr 1, 2008
Loading...

Share This Page