Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #3599 > unrolled thread
| Started by | Nikos Chantziaras <realnc@arcor.de> |
|---|---|
| First post | 2011-04-14 00:38 +0300 |
| Last post | 2011-04-14 21:45 +0300 |
| Articles | 4 on this page of 24 — 9 participants |
Back to article view | Back to comp.lang.c++
Initializing iterators to one past end() in for loops Nikos Chantziaras <realnc@arcor.de> - 2011-04-14 00:38 +0300
Re: Initializing iterators to one past end() in for loops Leigh Johnston <leigh@i42.co.uk> - 2011-04-13 22:46 +0100
Re: Initializing iterators to one past end() in for loops Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-04-13 23:48 +0200
Re: Initializing iterators to one past end() in for loops Leigh Johnston <leigh@i42.co.uk> - 2011-04-13 22:50 +0100
Re: Initializing iterators to one past end() in for loops Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-04-14 00:23 +0200
Re: Initializing iterators to one past end() in for loops Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-04-14 00:32 +0200
Re: Initializing iterators to one past end() in for loops Noah Roberts <dont@email.me> - 2011-04-13 17:16 -0700
Re: Initializing iterators to one past end() in for loops Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-04-14 05:57 +0200
Re: Initializing iterators to one past end() in for loops Leigh Johnston <leigh@i42.co.uk> - 2011-04-14 14:29 +0100
Re: Initializing iterators to one past end() in for loops Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-04-14 17:57 +0200
Re: Initializing iterators to one past end() in for loops Leigh Johnston <leigh@i42.co.uk> - 2011-04-14 17:56 +0100
Re: Initializing iterators to one past end() in for loops Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-04-14 19:33 +0200
Re: Initializing iterators to one past end() in for loops Noah Roberts <dont@email.me> - 2011-04-14 09:54 -0700
Re: Initializing iterators to one past end() in for loops Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-04-14 20:08 +0200
Re: Initializing iterators to one past end() in for loops gwowen <gwowen@gmail.com> - 2011-04-13 14:49 -0700
Re: Initializing iterators to one past end() in for loops Sam <sam@email-scan.com> - 2011-04-13 16:58 -0500
Re: Initializing iterators to one past end() in for loops Nikos Chantziaras <realnc@arcor.de> - 2011-04-14 01:07 +0300
Re: Initializing iterators to one past end() in for loops Ian Collins <ian-news@hotmail.com> - 2011-04-14 10:12 +1200
Re: Initializing iterators to one past end() in for loops gwowen <gwowen@gmail.com> - 2011-04-13 15:24 -0700
Re: Initializing iterators to one past end() in for loops Paavo Helde <myfirstname@osa.pri.ee> - 2011-04-13 23:05 -0500
Re: Initializing iterators to one past end() in for loops Ian Collins <ian-news@hotmail.com> - 2011-04-14 16:20 +1200
Re: Initializing iterators to one past end() in for loops Paavo Helde <myfirstname@osa.pri.ee> - 2011-04-13 23:52 -0500
Re: Initializing iterators to one past end() in for loops Jeff Flinn <TriumphSprint2000@hotmail.com> - 2011-04-14 07:49 -0400
Re: Initializing iterators to one past end() in for loops Nikos Chantziaras <realnc@arcor.de> - 2011-04-14 21:45 +0300
Page 2 of 2 — ← Prev page 1 [2]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-04-14 16:20 +1200 |
| Message-ID | <90nb0sFeeiU14@mid.individual.net> |
| In reply to | #3637 |
On 04/14/11 04:05 PM, Paavo Helde wrote:
> Nikos Chantziaras<realnc@arcor.de> wrote in news:io56qc$cu8$1
> @news.grnet.gr:
>> Thanks for all the responses. But I've made a mistake in my provided
>> example :-P In the second loop, I'm using an std::list, not a vector:
>>
>> std::list<int> lst;
>> typedef std::list<int>::iterator it_t;
>> for (it_t i = lst.begin() + 1; i != lst.end(); ++i)
>> // do something with *i
>>
>> (Converting some vectors to lists was the reason I came across this in
>> the first place.)
>>
>> I know it's not difficult to simply do something like:
>>
>> it_t i = lst.begin();
>> ++i;
>> for ( ; i != lst.end(); ++i)
>>
>> but I was wondering whether there's some neat way to do that inside the
>> for header, so that 'i' will not stay in scope after the loop.
>
> std::list<int> lst;
> typedef std::list<int>::iterator it_t;
> // populate list
>
> if (!lst.empty()) {
> for (it_t i = std::next(lst.begin()); i != lst.end(); ++i) {
For those using C++0x compilers!
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Date | 2011-04-13 23:52 -0500 |
| Message-ID | <Xns9EC75024CB95Fmyfirstnameosapriee@216.196.109.131> |
| In reply to | #3638 |
Ian Collins <ian-news@hotmail.com> wrote in news:90nb0sFeeiU14
@mid.individual.net:
> On 04/14/11 04:05 PM, Paavo Helde wrote:
>> for (it_t i = std::next(lst.begin()); i != lst.end(); ++i) {
>
> For those using C++0x compilers!
Right. It is working in VS2010 so I was sure this could not be something
very advanced.
Cheers
Paavo
[toc] | [prev] | [next] | [standalone]
| From | Jeff Flinn <TriumphSprint2000@hotmail.com> |
|---|---|
| Date | 2011-04-14 07:49 -0400 |
| Message-ID | <io6n14$qdu$1@dont-email.me> |
| In reply to | #3638 |
Ian Collins wrote:
> On 04/14/11 04:05 PM, Paavo Helde wrote:
>> Nikos Chantziaras<realnc@arcor.de> wrote in news:io56qc$cu8$1
>> @news.grnet.gr:
>>> Thanks for all the responses. But I've made a mistake in my provided
>>> example :-P In the second loop, I'm using an std::list, not a vector:
>>>
>>> std::list<int> lst;
>>> typedef std::list<int>::iterator it_t;
>>> for (it_t i = lst.begin() + 1; i != lst.end(); ++i)
>>> // do something with *i
>>>
>>> (Converting some vectors to lists was the reason I came across this in
>>> the first place.)
>>>
>>> I know it's not difficult to simply do something like:
>>>
>>> it_t i = lst.begin();
>>> ++i;
>>> for ( ; i != lst.end(); ++i)
>>>
>>> but I was wondering whether there's some neat way to do that inside the
>>> for header, so that 'i' will not stay in scope after the loop.
>>
>> std::list<int> lst;
>> typedef std::list<int>::iterator it_t;
>> // populate list
>>
>> if (!lst.empty()) {
>> for (it_t i = std::next(lst.begin()); i != lst.end(); ++i) {
>
> For those using C++0x compilers!
>
for (it_t i = boost::next(lst.begin()); i != lst.end(); ++i) {
For those with most any compiler!
Jeff
[toc] | [prev] | [next] | [standalone]
| From | Nikos Chantziaras <realnc@arcor.de> |
|---|---|
| Date | 2011-04-14 21:45 +0300 |
| Message-ID | <io7fbq$fua$1@news.grnet.gr> |
| In reply to | #3637 |
On 04/14/2011 07:05 AM, Paavo Helde wrote:
> Nikos Chantziaras<realnc@arcor.de> wrote in news:io56qc$cu8$1
> @news.grnet.gr:
>> Thanks for all the responses. But I've made a mistake in my provided
>> example :-P In the second loop, I'm using an std::list, not a vector:
>>
>> std::list<int> lst;
>> typedef std::list<int>::iterator it_t;
>> for (it_t i = lst.begin() + 1; i != lst.end(); ++i)
>> // do something with *i
>>
>> (Converting some vectors to lists was the reason I came across this in
>> the first place.)
>>
>> I know it's not difficult to simply do something like:
>>
>> it_t i = lst.begin();
>> ++i;
>> for ( ; i != lst.end(); ++i)
>>
>> but I was wondering whether there's some neat way to do that inside the
>> for header, so that 'i' will not stay in scope after the loop.
> [...]
>
> if (!lst.empty()) {
> for (it_t i = std::next(lst.begin()); i != lst.end(); ++i) {
> // do something
> }
> }
Yep, that looks nicer! It's C++0x, but seems to be supported well
enough by now.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.c++
csiph-web