Topic: Additional counters in for each loop
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Fri, 16 Jan 2015 17:00:31 -0800 (PST)
Raw View
------=_Part_1379_1407668312.1421456431852
Content-Type: multipart/alternative;
boundary="----=_Part_1380_2001464432.1421456431852"
------=_Part_1380_2001464432.1421456431852
Content-Type: text/plain; charset=UTF-8
In for loops it is often useful to add extra statements at the end of the
loop to do more things at the increment stage.
int index = 0;
for(auto iter = v.begin(), e =v.end(); iter!=e; ++iter, ++index) { }
This situation is ideal because index will always be incremented when
continue statements are executed. We don't have to copy and paste ++index;
to each continue path and carefully check we didn't mess it up.
We don't have the ability to specify additional loop counters like index
when we use for-each loops.
This seems like a relatively straightforward syntax addition to for each
loops:
int index = 0;
for(auto& val: collection; ++index) { }
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1380_2001464432.1421456431852
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">In for loops it is often useful to add extra statements at=
the end of the loop to do more things at the increment stage.<div><br></di=
v><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, =
187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code c=
lass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> index </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">for</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> iter </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=3D</span><font color=3D"#000000"><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> v</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">begin</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(),</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> e </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">v</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.<=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">end</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> iter</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">!=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">e</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">++</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">iter</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">++</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">index</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span></font></div></code></div><div><br></div>This situation is ideal =
because index will always be incremented when continue statements are execu=
ted. We don't have to copy and paste ++index; to each continue path and car=
efully check we didn't mess it up.</div><div><br></div><div>We don't have t=
he ability to specify additional loop counters like index when we use for-e=
ach loops. </div><div><br></div><div>This seems like a relatively stra=
ightforward syntax addition to for each loops:</div><div><div class=3D"pret=
typrint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-wo=
rd; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div=
class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> index </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">for</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">auto</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> val</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">:</span><font color=3D"#000000"><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> collection</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
++</span><span style=3D"color: #000;" class=3D"styled-by-prettify">index</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">}</span></font></div></code></div></div><div><br>=
</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1380_2001464432.1421456431852--
------=_Part_1379_1407668312.1421456431852--
.
Author: Sean Middleditch <sean.middleditch@gmail.com>
Date: Fri, 16 Jan 2015 21:45:45 -0800 (PST)
Raw View
------=_Part_1227_917809915.1421473545186
Content-Type: multipart/alternative;
boundary="----=_Part_1228_256205004.1421473545187"
------=_Part_1228_256205004.1421473545187
Content-Type: text/plain; charset=UTF-8
This example would likely be better served with a range adaptor ("view" in
Eric Niebler's parlance) that keeps both an index and iterator together.
On Friday, January 16, 2015 at 5:00:31 PM UTC-8, Matthew Fioravante wrote:
>
> In for loops it is often useful to add extra statements at the end of the
> loop to do more things at the increment stage.
>
> int index = 0;
> for(auto iter = v.begin(), e =v.end(); iter!=e; ++iter, ++index) { }
>
> This situation is ideal because index will always be incremented when
> continue statements are executed. We don't have to copy and paste ++index;
> to each continue path and carefully check we didn't mess it up.
>
> We don't have the ability to specify additional loop counters like index
> when we use for-each loops.
>
> This seems like a relatively straightforward syntax addition to for each
> loops:
> int index = 0;
> for(auto& val: collection; ++index) { }
>
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1228_256205004.1421473545187
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">This example would likely be better served with a range ad=
aptor ("view" in Eric Niebler's parlance) that keeps both an index and iter=
ator together.<div><br><div>On Friday, January 16, 2015 at 5:00:31 PM UTC-8=
, Matthew Fioravante wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v dir=3D"ltr">In for loops it is often useful to add extra statements at th=
e end of the loop to do more things at the increment stage.<div><br></div><=
div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;ba=
ckground-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">int<=
/span><span style=3D"color:#000"> index </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#066">0</=
span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></sp=
an><span style=3D"color:#008">for</span><span style=3D"color:#660">(</span>=
<span style=3D"color:#008">auto</span><span style=3D"color:#000"> iter </sp=
an><span style=3D"color:#660">=3D</span><font color=3D"#000000"><span style=
=3D"color:#000"> v</span><span style=3D"color:#660">.</span><span style=3D"=
color:#008">begin</span><span style=3D"color:#660">(),</span><span style=3D=
"color:#000"> e </span><span style=3D"color:#660">=3D</span><span style=3D"=
color:#000">v</span><span style=3D"color:#660">.</span><span style=3D"color=
:#008">end</span><span style=3D"color:#660">();</span><span style=3D"color:=
#000"> iter</span><span style=3D"color:#660">!=3D</span><span style=3D"colo=
r:#000">e</span><span style=3D"color:#660">;</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">++</span><span style=3D"color:#000">i=
ter</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">++</span><span style=3D"color:#000">index</=
span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#660">}</span><span style=3D"color:#000"> </span></font></d=
iv></code></div><div><br></div>This situation is ideal because index will a=
lways be incremented when continue statements are executed. We don't have t=
o copy and paste ++index; to each continue path and carefully check we didn=
't mess it up.</div><div><br></div><div>We don't have the ability to specif=
y additional loop counters like index when we use for-each loops. </di=
v><div><br></div><div>This seems like a relatively straightforward syntax a=
ddition to for each loops:</div><div><div style=3D"border:1px solid rgb(187=
,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><di=
v><span style=3D"color:#008">int</span><span style=3D"color:#000"> index </=
span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#066">0</span><span style=3D"color:#660">;</span><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#008">for</span><sp=
an style=3D"color:#660">(</span><span style=3D"color:#008">auto</span><span=
style=3D"color:#660">&</span><span style=3D"color:#000"> val</span><sp=
an style=3D"color:#660">:</span><font color=3D"#000000"><span style=3D"colo=
r:#000"> collection</span><span style=3D"color:#660">;</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">++</span><span style=3D"col=
or:#000">index</span><span style=3D"color:#660">)</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">}</span></font></div></code></div></d=
iv><div><br></div></div></blockquote></div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1228_256205004.1421473545187--
------=_Part_1227_917809915.1421473545186--
.
Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 16 Jan 2015 22:13:01 -0800 (PST)
Raw View
------=_Part_1406_377764186.1421475181113
Content-Type: multipart/alternative;
boundary="----=_Part_1407_1121013570.1421475181113"
------=_Part_1407_1121013570.1421475181113
Content-Type: text/plain; charset=UTF-8
Well, let's go further. Why not write the following way
for(int index = 0; auto& val: collection; ++index) { }
because index is not used outside the loop? :)
On Saturday, January 17, 2015 at 4:00:31 AM UTC+3, Matthew Fioravante wrote:
> In for loops it is often useful to add extra statements at the end of the
> loop to do more things at the increment stage.
>
> int index = 0;
> for(auto iter = v.begin(), e =v.end(); iter!=e; ++iter, ++index) { }
>
> This situation is ideal because index will always be incremented when
> continue statements are executed. We don't have to copy and paste ++index;
> to each continue path and carefully check we didn't mess it up.
>
> We don't have the ability to specify additional loop counters like index
> when we use for-each loops.
>
> This seems like a relatively straightforward syntax addition to for each
> loops:
> int index = 0;
> for(auto& val: collection; ++index) { }
>
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1407_1121013570.1421475181113
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Well, let's go further. Why not write the following w=
ay</div><div><br></div><div><div style=3D"border: 1px solid rgb(187, 187, 1=
87); border-image: none; -ms-word-wrap: break-word; background-color: rgb(2=
50, 250, 250);"><code><div><span style=3D"color: rgb(0, 0, 136);">for</span=
><span style=3D"color: rgb(102, 102, 0);">(int index =3D 0; </span><span st=
yle=3D"color: rgb(0, 0, 136);">auto</span><span style=3D"color: rgb(102, 10=
2, 0);">&</span><span style=3D"color: rgb(0, 0, 0);"> val</span><span s=
tyle=3D"color: rgb(102, 102, 0);">:</span><font color=3D"#000000"><span sty=
le=3D"color: rgb(0, 0, 0);"> collection</span><span style=3D"color: rgb(102=
, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"> </span><span styl=
e=3D"color: rgb(102, 102, 0);">++</span><span style=3D"color: rgb(0, 0, 0);=
">index</span><span style=3D"color: rgb(102, 102, 0);">)</span><span style=
=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">=
{</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: =
rgb(102, 102, 0);">}</span></font></div></code></div></div><p><br></p><div>=
because index is not used outside the loop? :)</div><div><br><br>On Saturda=
y, January 17, 2015 at 4:00:31 AM UTC+3, Matthew Fioravante wrote:</div><bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-=
left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; b=
order-left-style: solid;"><div dir=3D"ltr">In for loops it is often useful =
to add extra statements at the end of the loop to do more things at the inc=
rement stage.<div><br></div><div><div style=3D"border: 1px solid rgb(187, 1=
87, 187); border-image: none; -ms-word-wrap: break-word; background-color: =
rgb(250, 250, 250);"><code><div><span style=3D"color: rgb(0, 0, 136);">int<=
/span><span style=3D"color: rgb(0, 0, 0);"> index </span><span style=3D"col=
or: rgb(102, 102, 0);">=3D</span><span style=3D"color: rgb(0, 0, 0);"> </sp=
an><span style=3D"color: rgb(0, 102, 102);">0</span><span style=3D"color: r=
gb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br></span><=
span style=3D"color: rgb(0, 0, 136);">for</span><span style=3D"color: rgb(1=
02, 102, 0);">(</span><span style=3D"color: rgb(0, 0, 136);">auto</span><sp=
an style=3D"color: rgb(0, 0, 0);"> iter </span><span style=3D"color: rgb(10=
2, 102, 0);">=3D</span><font color=3D"#000000"><span style=3D"color: rgb(0,=
0, 0);"> v</span><span style=3D"color: rgb(102, 102, 0);">.</span><span st=
yle=3D"color: rgb(0, 0, 136);">begin</span><span style=3D"color: rgb(102, 1=
02, 0);">(),</span><span style=3D"color: rgb(0, 0, 0);"> e </span><span sty=
le=3D"color: rgb(102, 102, 0);">=3D</span><span style=3D"color: rgb(0, 0, 0=
);">v</span><span style=3D"color: rgb(102, 102, 0);">.</span><span style=3D=
"color: rgb(0, 0, 136);">end</span><span style=3D"color: rgb(102, 102, 0);"=
>();</span><span style=3D"color: rgb(0, 0, 0);"> iter</span><span style=3D"=
color: rgb(102, 102, 0);">!=3D</span><span style=3D"color: rgb(0, 0, 0);">e=
</span><span style=3D"color: rgb(102, 102, 0);">;</span><span style=3D"colo=
r: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">++</span=
><span style=3D"color: rgb(0, 0, 0);">iter</span><span style=3D"color: rgb(=
102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0);"> </span><span s=
tyle=3D"color: rgb(102, 102, 0);">++</span><span style=3D"color: rgb(0, 0, =
0);">index</span><span style=3D"color: rgb(102, 102, 0);">)</span><span sty=
le=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);=
">{</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color=
: rgb(102, 102, 0);">}</span><span style=3D"color: rgb(0, 0, 0);"> </span><=
/font></div></code></div><div><br></div>This situation is ideal because ind=
ex will always be incremented when continue statements are executed. We don=
't have to copy and paste ++index; to each continue path and carefully chec=
k we didn't mess it up.</div><div><br></div><div>We don't have the ability =
to specify additional loop counters like index when we use for-each loops.&=
nbsp;</div><div><br></div><div>This seems like a relatively straightforward=
syntax addition to for each loops:</div><div><div style=3D"border: 1px sol=
id rgb(187, 187, 187); border-image: none; -ms-word-wrap: break-word; backg=
round-color: rgb(250, 250, 250);"><code><div><span style=3D"color: rgb(0, 0=
, 136);">int</span><span style=3D"color: rgb(0, 0, 0);"> index </span><span=
style=3D"color: rgb(102, 102, 0);">=3D</span><span style=3D"color: rgb(0, =
0, 0);"> </span><span style=3D"color: rgb(0, 102, 102);">0</span><span styl=
e=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"=
><br></span><span style=3D"color: rgb(0, 0, 136);">for</span><span style=3D=
"color: rgb(102, 102, 0);">(</span><span style=3D"color: rgb(0, 0, 136);">a=
uto</span><span style=3D"color: rgb(102, 102, 0);">&</span><span style=
=3D"color: rgb(0, 0, 0);"> val</span><span style=3D"color: rgb(102, 102, 0)=
;">:</span><font color=3D"#000000"><span style=3D"color: rgb(0, 0, 0);"> co=
llection</span><span style=3D"color: rgb(102, 102, 0);">;</span><span style=
=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">=
++</span><span style=3D"color: rgb(0, 0, 0);">index</span><span style=3D"co=
lor: rgb(102, 102, 0);">)</span><span style=3D"color: rgb(0, 0, 0);"> </spa=
n><span style=3D"color: rgb(102, 102, 0);">{</span><span style=3D"color: rg=
b(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">}</span></fon=
t></div></code></div></div><div><br></div></div></blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1407_1121013570.1421475181113--
------=_Part_1406_377764186.1421475181113--
.
Author: Sean Middleditch <sean@middleditch.us>
Date: Sat, 17 Jan 2015 15:33:06 -0800
Raw View
On Fri, Jan 16, 2015 at 10:13 PM, Vlad from Moscow <vlad.moscow@mail.ru> wrote:
> Well, let's go further. Why not write the following way
>
> for(int index = 0; auto& val: collection; ++index) { }
That seems a bit magical. It's changing `for` in pretty significant
ways: (1) variables are now declared in the second clause, (2) there's
no correlation intended between the clauses, (3) the control statement
has three clauses but only one of them has anything to do with the
actual loop control.
I see no reason that this weird construct would be more logical or
more idiomatic than:
for (auto& i : ipairs(collection))
// i.first == index
// i.second == std::ref<iterator>
And the awkwardness of the pair as the value being resolved by the far
more general and useful feature of destructuring assignment, e.g.:
for (auto {index, &value} : ipairs(collection))
Or whatever syntax destructuring assignment takes (and assuming
someone writes a decent proposal to actually add such a feature...
please?).
(and of course in STL fashion, `ipairs` would be longer and more
specifically named, but not specific enough to avoid ambiguity or
confusion down the line)
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: gmisocpp@gmail.com
Date: Sat, 17 Jan 2015 16:37:40 -0800 (PST)
Raw View
------=_Part_1469_678749376.1421541460916
Content-Type: multipart/alternative;
boundary="----=_Part_1470_307629568.1421541460916"
------=_Part_1470_307629568.1421541460916
Content-Type: text/plain; charset=UTF-8
On Sunday, January 18, 2015 at 12:33:08 PM UTC+13, Sean Middleditch wrote:
>
> On Fri, Jan 16, 2015 at 10:13 PM, Vlad from Moscow <vlad....@mail.ru
> <javascript:>> wrote:
> > Well, let's go further. Why not write the following way
> >
> > for(int index = 0; auto& val: collection; ++index) { }
>
> That seems a bit magical. It's changing `for` in pretty significant
> ways: (1) variables are now declared in the second clause, (2) there's
> no correlation intended between the clauses, (3) the control statement
> has three clauses but only one of them has anything to do with the
> actual loop control.
>
> I see no reason that this weird construct would be more logical or
> more idiomatic than:
>
> for (auto& i : ipairs(collection))
> // i.first == index
> // i.second == std::ref<iterator>
>
> And the awkwardness of the pair as the value being resolved by the far
> more general and useful feature of destructuring assignment, e.g.:
>
> for (auto {index, &value} : ipairs(collection))
>
> Or whatever syntax destructuring assignment takes (and assuming
> someone writes a decent proposal to actually add such a feature...
> please?).
>
> (and of course in STL fashion, `ipairs` would be longer and more
> specifically named, but not specific enough to avoid ambiguity or
> confusion down the line)
>
I suggested the same as what the OP proposed some time ago.
https://groups.google.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/Improvements$20to$20N3994$20-$20Steps$20to$20make$20loop$20syntax$20consistent$20again./std-proposals/zso4qh-KbTk/Gtu4jVTK86kJ
The subject was: "Improvements to N3994 - Steps to make loop syntax
consistent again."
People weren't excited by the idea but nobody proved that there was
anything magical or Impossible about the idea.
Just most people didn't warm to it.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1470_307629568.1421541460916
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, January 18, 2015 at 12:33:08 PM UTC+13,=
Sean Middleditch wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204)=
; border-left-width: 1px; border-left-style: solid;">On Fri, Jan 16, 2015 a=
t 10:13 PM, Vlad from Moscow <<a onmousedown=3D"this.href=3D'javascript:=
';return true;" onclick=3D"this.href=3D'javascript:';return true;" href=3D"=
javascript:" target=3D"_blank" rel=3D"nofollow" gdf-obfuscated-mailto=3D"5n=
PyaS7LurgJ">vlad....@mail.ru</a>> wrote:
<br>> Well, let's go further. Why not write the following way
<br>>
<br>> for(int index =3D 0; auto& val: collection; ++index) { }
<br>
<br>That seems a bit magical. It's changing `for` in pretty significant
<br>ways: (1) variables are now declared in the second clause, (2) there's
<br>no correlation intended between the clauses, (3) the control statement
<br>has three clauses but only one of them has anything to do with the
<br>actual loop control.
<br>
<br>I see no reason that this weird construct would be more logical or
<br>more idiomatic than:
<br>
<br> for (auto& i : ipairs(collection))
<br> // i.first =3D=3D index
<br> // i.second =3D=3D std::ref<iterator>
<br>
<br>And the awkwardness of the pair as the value being resolved by the far
<br>more general and useful feature of destructuring assignment, e.g.:
<br>
<br> for (auto {index, &value} : ipairs(collection))
<br>
<br>Or whatever syntax destructuring assignment takes (and assuming
<br>someone writes a decent proposal to actually add such a feature...
<br>please?).
<br>
<br>(and of course in STL fashion, `ipairs` would be longer and more
<br>specifically named, but not specific enough to avoid ambiguity or
<br>confusion down the line)
<br></blockquote><div><br></div><div>I suggested the same as what=
the OP proposed some time ago.</div><div><a href=3D"https://groups.google.=
com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/Improvements$20t=
o$20N3994$20-$20Steps$20to$20make$20loop$20syntax$20consistent$20again./std=
-proposals/zso4qh-KbTk/Gtu4jVTK86kJ">https://groups.google.com/a/isocpp.org=
/forum/?fromgroups#!searchin/std-proposals/Improvements$20to$20N3994$20-$20=
Steps$20to$20make$20loop$20syntax$20consistent$20again./std-proposals/zso4q=
h-KbTk/Gtu4jVTK86kJ</a> </div><div><br></div><div>The subject was: "Im=
provements to N3994 - Steps to make loop syntax consistent again."</div><di=
v><br></div><div>People weren't excited by the idea but nobody proved that =
there was anything magical or Impossible about the idea.</div><div>Just mos=
t people didn't warm to it.</div><div><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1470_307629568.1421541460916--
------=_Part_1469_678749376.1421541460916--
.
Author: olena.reznikova@gmail.com
Date: Sun, 18 Jan 2015 06:36:45 -0800 (PST)
Raw View
------=_Part_2480_896487045.1421591805221
Content-Type: multipart/alternative;
boundary="----=_Part_2481_512497963.1421591805221"
------=_Part_2481_512497963.1421591805221
Content-Type: text/plain; charset=UTF-8
On Saturday, January 17, 2015 at 6:33:08 PM UTC-5, Sean Middleditch wrote:
>
>
>
> I see no reason that this weird construct would be more logical or
> more idiomatic than:
>
> for (auto& i : ipairs(collection))
> // i.first == index
> // i.second == std::ref<iterator>
>
> And the awkwardness of the pair as the value being resolved by the far
> more general and useful feature of destructuring assignment, e.g.:
>
> for (auto {index, &value} : ipairs(collection))
>
> Or whatever syntax destructuring assignment takes (and assuming
> someone writes a decent proposal to actually add such a feature...
> please?).
>
>
Implementing the feature as a library is usually thought to be a better
solution but I'm still a bit skeptical. The problem I see with using a
library solution is that it would take an awful lot of boilerplate code
just to write your own custom range adapter.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2481_512497963.1421591805221
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Saturday, January 17, 2015 at 6:33:08 PM UTC-5,=
Sean Middleditch wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br>
<br>I see no reason that this weird construct would be more logical or
<br>more idiomatic than:
<br>
<br> for (auto& i : ipairs(collection))
<br> // i.first =3D=3D index
<br> // i.second =3D=3D std::ref<iterator>
<br>
<br>And the awkwardness of the pair as the value being resolved by the far
<br>more general and useful feature of destructuring assignment, e.g.:
<br>
<br> for (auto {index, &value} : ipairs(collection))
<br>
<br>Or whatever syntax destructuring assignment takes (and assuming
<br>someone writes a decent proposal to actually add such a feature...
<br>please?).
<br><br></blockquote><div><br></div><div>Implementing the feature as a libr=
ary is usually thought to be a better solution but I'm still a bit skeptica=
l. The problem I see with using a library solution is that it would take an=
awful lot of boilerplate code just to write your own custom range adapter.=
</div><div> </div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_2481_512497963.1421591805221--
------=_Part_2480_896487045.1421591805221--
.
Author: Sean Middleditch <sean.middleditch@gmail.com>
Date: Sun, 18 Jan 2015 13:51:46 -0800 (PST)
Raw View
------=_Part_2003_286560678.1421617906682
Content-Type: multipart/alternative;
boundary="----=_Part_2004_1566978572.1421617906682"
------=_Part_2004_1566978572.1421617906682
Content-Type: text/plain; charset=UTF-8
On Sunday, January 18, 2015 at 6:36:45 AM UTC-8, olena.r...@gmail.com wrote:
>
>
> Implementing the feature as a library is usually thought to be a better
> solution but I'm still a bit skeptical. The problem I see with using a
> library solution is that it would take an awful lot of boilerplate code
> just to write your own custom range adapter.
>
So propose that adaptor for the standard library. It's not like a language
change is likely to be rolled out before a standard library change.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2004_1566978572.1421617906682
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, January 18, 2015 at 6:36:45 AM UTC-8, olena.r..=
..@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><div><br></div><div>Implementing the feature as a library is usually t=
hought to be a better solution but I'm still a bit skeptical. The problem I=
see with using a library solution is that it would take an awful lot of bo=
ilerplate code just to write your own custom range adapter. </div></di=
v></blockquote><div><br></div><div>So propose that adaptor for the standard=
library. It's not like a language change is likely to be rolled out before=
a standard library change.</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_2004_1566978572.1421617906682--
------=_Part_2003_286560678.1421617906682--
.
Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Tue, 20 Jan 2015 09:34:29 -0800 (PST)
Raw View
------=_Part_651_800152448.1421775269412
Content-Type: multipart/alternative;
boundary="----=_Part_652_619596022.1421775269412"
------=_Part_652_619596022.1421775269412
Content-Type: text/plain; charset=UTF-8
On Sunday, January 18, 2015 at 12:33:08 AM UTC+1, Sean Middleditch wrote:
>
> On Fri, Jan 16, 2015 at 10:13 PM, Vlad from Moscow <vlad....@mail.ru
> <javascript:>> wrote:
> > Well, let's go further. Why not write the following way
> >
> > for(int index = 0; auto& val: collection; ++index) { }
>
> That seems a bit magical. It's changing `for` in pretty significant
> ways: (1) variables are now declared in the second clause,
>
Already possible
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_652_619596022.1421775269412
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, January 18, 2015 at 12:33:08 AM UTC+1, Sean Mid=
dleditch wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Fri, Jan 16,=
2015 at 10:13 PM, Vlad from Moscow <<a href=3D"javascript:" target=3D"_=
blank" gdf-obfuscated-mailto=3D"5nPyaS7LurgJ" rel=3D"nofollow" onmousedown=
=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascr=
ipt:';return true;">vlad....@mail.ru</a>> wrote:
<br>> Well, let's go further. Why not write the following way
<br>>
<br>> for(int index =3D 0; auto& val: collection; ++index) { }
<br>
<br>That seems a bit magical. It's changing `for` in pretty significant
<br>ways: (1) variables are now declared in the second clause, <br></b=
lockquote><div><br></div><div>Already possible </div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_652_619596022.1421775269412--
------=_Part_651_800152448.1421775269412--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Tue, 20 Jan 2015 18:26:20 -0800 (PST)
Raw View
------=_Part_2446_498630582.1421807180401
Content-Type: multipart/alternative;
boundary="----=_Part_2447_1003001080.1421807180401"
------=_Part_2447_1003001080.1421807180401
Content-Type: text/plain; charset=UTF-8
On Sunday, January 18, 2015 at 4:51:46 PM UTC-5, Sean Middleditch wrote:
>
> On Sunday, January 18, 2015 at 6:36:45 AM UTC-8, olena.r...@gmail.com
> wrote:
>>
>>
>> Implementing the feature as a library is usually thought to be a better
>> solution but I'm still a bit skeptical. The problem I see with using a
>> library solution is that it would take an awful lot of boilerplate code
>> just to write your own custom range adapter.
>>
>
> So propose that adaptor for the standard library. It's not like a language
> change is likely to be rolled out before a standard library change.
>
A standard adapter for iterating of indices is fine, but people will want
to do more than that. Such an adapter needs to be configurable to allow any
number of additional iteration variables of any type to be defined and have
customized increment logic for each one. I'm not sure any library solution
can do that cleaner and easier than a simple language change.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2447_1003001080.1421807180401
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, January 18, 2015 at 4:51:46 PM UTC-5, S=
ean Middleditch wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">On Sunday, January 18, 2015 at 6:36:45 AM UTC-8, <a>olena.r...@gma=
il.com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin=
-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><=
div><br></div><div>Implementing the feature as a library is usually thought=
to be a better solution but I'm still a bit skeptical. The problem I see w=
ith using a library solution is that it would take an awful lot of boilerpl=
ate code just to write your own custom range adapter. </div></div></bl=
ockquote><div><br></div><div>So propose that adaptor for the standard libra=
ry. It's not like a language change is likely to be rolled out before a sta=
ndard library change.</div></div></blockquote><div><br></div><div>A standar=
d adapter for iterating of indices is fine, but people will want to do more=
than that. Such an adapter needs to be configurable to allow any number of=
additional iteration variables of any type to be defined and have customiz=
ed increment logic for each one. I'm not sure any library solution can do t=
hat cleaner and easier than a simple language change.</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_2447_1003001080.1421807180401--
------=_Part_2446_498630582.1421807180401--
.