Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #10108

Defining iterator type through container object type

From Urs Thuermann <urs@isnogud.escape.de>
Newsgroups comp.lang.c++
Subject Defining iterator type through container object type
Date 2011-09-14 23:51 +0200
Organization escape e.V. - Verein zur Foerderung der Datenkommunikation
Message-ID <ygf7h5ayere.fsf@janus.isnogud.escape.de> (permalink)

Show all headers | View raw


Can I define an iterator for an object of a standard container class
without using the concrete type of that container object?

I tried things like

    1 #include <list>
    2 void foo(std::list<int> ilist) {
    3     ilist.iterator it;
    4     for (it = ilist.begin(); it != ilist.end(); ++it) { *it; }
    5 }

and

    1 #include <list>
    2 void foo(std::list<int> ilist) {
    3     typeof(ilist)::iterator it;
    4     for (it = ilist.begin(); it != ilist.end(); ++it) { *it; }
    5 }

For the first code I get 

    foo.cc:3:11: error: invalid use of 'std::list<int>::iterator'

so at least ilist.iterator seems indeed to be understood as
std::list<int>::iterator.  In the second case I get

    foo.cc:3:29: error: expected initializer before 'it'

Is there a way to define the iterator without using std::list<int>::iterator
explicitly?

urs

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Defining iterator type through container object type Urs Thuermann <urs@isnogud.escape.de> - 2011-09-14 23:51 +0200
  Re: Defining iterator type through container object type Ian Collins <ian-news@hotmail.com> - 2011-09-15 10:25 +1200
    Re: Defining iterator type through container object type Juha Nieminen <nospam@thanks.invalid> - 2011-09-15 06:49 +0000
      Re: Defining iterator type through container object type Marc <marc.glisse@gmail.com> - 2011-09-15 08:03 +0000
        Re: Defining iterator type through container object type Urs Thuermann <urs@isnogud.escape.de> - 2011-11-03 14:30 +0100
          Re: Defining iterator type through container object type Marc <marc.glisse@gmail.com> - 2011-11-03 18:17 +0000
            Re: Defining iterator type through container object type Urs Thuermann <urs@isnogud.escape.de> - 2011-11-04 15:10 +0100

csiph-web