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


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

Re: Defining iterator type through container object type

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: Defining iterator type through container object type
Date Thu, 15 Sep 2011 10:25:31 +1200
Lines 37
Message-ID <9dcnusF786U1@mid.individual.net> (permalink)
References <ygf7h5ayere.fsf@janus.isnogud.escape.de>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net N4Vf7yjkvdxnAUKtPShbpAxMt9nJA7S3ew6EMiSOSpGskB5Bvz
Cancel-Lock sha1:yJYgV/eWbUAWpfZHWrZjf9azFUc=
User-Agent Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4
In-Reply-To <ygf7h5ayere.fsf@janus.isnogud.escape.de>
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:10111

Show key headers only | View raw


On 09/15/11 09:51 AM, Urs Thuermann wrote:
> 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?

Only if your compiler supports the new auto keyword.  Otherwise use a 
typedef for the parameter type.

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | 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