Topic: for loops w/ reverse iteration


Author: Phil Bouchard <philippeb8@gmail.com>
Date: Tue, 28 Aug 2018 14:06:08 -0700 (PDT)
Raw View
------=_Part_1674_401905566.1535490368388
Content-Type: text/plain; charset="UTF-8"

Regarding the for loops with implicit iteration:

list<string> cars;

for (auto const & i : cars)
    ...

How about reverse iteration for consistency?

for (auto const & i !: cars)
    ...

Or a better syntax.


Regards,
-Phil
www.fornux.com

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f96b3ed7-06a7-497a-b3e3-831495ae9b2f%40isocpp.org.

------=_Part_1674_401905566.1535490368388--

.


Author: Nevin Liber <nevin@eviloverlord.com>
Date: Tue, 28 Aug 2018 16:17:08 -0500
Raw View
--0000000000007d699b0574855f63
Content-Type: text/plain; charset="UTF-8"

On Tue, Aug 28, 2018 at 4:06 PM Phil Bouchard <philippeb8@gmail.com> wrote:

> Regarding the for loops with implicit iteration:
>
> list<string> cars;
>
> for (auto const & i : cars)
>     ...
>
> How about reverse iteration for consistency?
>
> for (auto const & i !: cars)
>     ...
>
> Or a better syntax.


reverse_view in The One Ranges Proposal p0896 <http://wg21.link/p0896> should
address that.
--
 Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  +1-847-691-1404

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGg_6%2BPEv86Keu6bjCcer2T8xn77vunuTjvFFqHi2zhO84mV%2Bg%40mail.gmail.com.

--0000000000007d699b0574855f63
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tue, Aug 28, 2018 at 4:06 PM Phil Bouchard &lt;<a href=
=3D"mailto:philippeb8@gmail.com">philippeb8@gmail.com</a>&gt; wrote:<br><di=
v class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Regarding the for lo=
ops with implicit iteration:<br>
<br>
list&lt;string&gt; cars;<br>
<br>
for (auto const &amp; i : cars)<br>
=C2=A0 =C2=A0 ...<br>
<br>
How about reverse iteration for consistency?<br>
<br>
for (auto const &amp; i !: cars)<br>
=C2=A0 =C2=A0 ...<br>
<br>
Or a better syntax.</blockquote><div><br></div><div>reverse_view in The One=
 Ranges Proposal <a href=3D"http://wg21.link/p0896">p0896</a>=C2=A0should a=
ddress that.<br></div></div>-- <br><div dir=3D"ltr" class=3D"gmail_signatur=
e" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr=
"><div>=C2=A0Nevin &quot;:-)&quot; Liber=C2=A0 &lt;mailto:<a href=3D"mailto=
:nevin@eviloverlord.com" target=3D"_blank">nevin@eviloverlord.com</a>&gt; =
=C2=A0+1-847-691-1404</div></div></div></div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAGg_6%2BPEv86Keu6bjCcer2T8xn77vunuTj=
vFFqHi2zhO84mV%2Bg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGg_6%2BPEv8=
6Keu6bjCcer2T8xn77vunuTjvFFqHi2zhO84mV%2Bg%40mail.gmail.com</a>.<br />

--0000000000007d699b0574855f63--

.


Author: Phil Bouchard <philippeb8@gmail.com>
Date: Tue, 28 Aug 2018 15:28:49 -0700 (PDT)
Raw View
------=_Part_1741_281447288.1535495329880
Content-Type: multipart/alternative;
 boundary="----=_Part_1742_459365959.1535495329880"

------=_Part_1742_459365959.1535495329880
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable



On Tuesday, August 28, 2018 at 5:17:47 PM UTC-4, Nevin ":-)" Liber wrote:
>
> On Tue, Aug 28, 2018 at 4:06 PM Phil Bouchard <phili...@gmail.com=20
> <javascript:>> wrote:
>
>> Regarding the for loops with implicit iteration:
>>
>> list<string> cars;
>>
>> for (auto const & i : cars)
>>     ...
>>
>> How about reverse iteration for consistency?
>>
>> for (auto const & i !: cars)
>>     ...
>>
>> Or a better syntax.
>
>
> reverse_view in The One Ranges Proposal p0896 <http://wg21.link/p0896> sh=
ould=20
> address that.
>
>
Ok. If it can be an elegant one-liner like the following then it's all good=
=20
with me:

vector is {0,1,2,3,4};=20
=20
for (int i : reverse_view{is})=20
    cout << i << =E2=80=99 =E2=80=99; // prints: 4 3 2 1 0


Thanks,
-Phil

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/5e6ffea4-4c7b-4da1-9602-bbd670ce1f8a%40isocpp.or=
g.

------=_Part_1742_459365959.1535495329880
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, August 28, 2018 at 5:17:47 PM UTC-4, N=
evin &quot;:-)&quot; Liber 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 Tue, Aug 28, 2018 at 4:06 PM Phil Bouchard &lt;<a hr=
ef=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"0cAhbDnfBwAJ"=
 rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return t=
rue;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">phili...@g=
mail.com</a>&gt; wrote:<br><div class=3D"gmail_quote"><blockquote class=3D"=
gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-=
left:1ex">Regarding the for loops with implicit iteration:<br>
<br>
list&lt;string&gt; cars;<br>
<br>
for (auto const &amp; i : cars)<br>
=C2=A0 =C2=A0 ...<br>
<br>
How about reverse iteration for consistency?<br>
<br>
for (auto const &amp; i !: cars)<br>
=C2=A0 =C2=A0 ...<br>
<br>
Or a better syntax.</blockquote><div><br></div><div>reverse_view in The One=
 Ranges Proposal <a href=3D"http://wg21.link/p0896" target=3D"_blank" rel=
=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.com/url?q\x=
3dhttp%3A%2F%2Fwg21.link%2Fp0896\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH0=
4um2BjvBbCfTEtSxRU84z5AsQA&#39;;return true;" onclick=3D"this.href=3D&#39;h=
ttp://www.google.com/url?q\x3dhttp%3A%2F%2Fwg21.link%2Fp0896\x26sa\x3dD\x26=
sntz\x3d1\x26usg\x3dAFQjCNH04um2BjvBbCfTEtSxRU84z5AsQA&#39;;return true;">p=
0896</a>=C2=A0should address that.<br></div></div><br></div></blockquote><d=
iv><br></div><div>Ok. If it can be an elegant one-liner like the following =
then it&#39;s all good with me:</div><div><br></div><div>vector<int> is {0,=
1,2,3,4};=C2=A0</int></div><div><int>=C2=A0</int></div><div><int>for (int i=
 :=C2=A0</int>reverse_view{is})=C2=A0</div><div><int>=C2=A0 =C2=A0 cout &lt=
;&lt; i &lt;&lt; =E2=80=99 =E2=80=99; // prints: 4 3 2 1 0</int></div><div>=
<int><br></int></div><div><int><br></int></div><div><int>Thanks,</int></div=
><div><int>-Phil</int></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/5e6ffea4-4c7b-4da1-9602-bbd670ce1f8a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5e6ffea4-4c7b-4da1-9602-bbd670ce1f8a=
%40isocpp.org</a>.<br />

------=_Part_1742_459365959.1535495329880--

------=_Part_1741_281447288.1535495329880--

.


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Wed, 29 Aug 2018 17:10:12 -0700 (PDT)
Raw View
------=_Part_6_1656031552.1535587812832
Content-Type: multipart/alternative;
 boundary="----=_Part_7_823486325.1535587812832"

------=_Part_7_823486325.1535587812832
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Tuesday, August 28, 2018 at 3:28:50 PM UTC-7, Phil Bouchard wrote:
>
> On Tuesday, August 28, 2018 at 5:17:47 PM UTC-4, Nevin ":-)" Liber wrote:
>>
>> On Tue, Aug 28, 2018 at 4:06 PM Phil Bouchard <phili...@gmail.com> wrote=
:
>>
>>> Regarding the for loops with implicit iteration:
>>>
>>> list<string> cars;
>>>
>>> for (auto const & i : cars)
>>>     ...
>>>
>>> How about reverse iteration for consistency?
>>>
>>> for (auto const & i !: cars)
>>>     ...
>>>
>>> Or a better syntax.
>>
>>
>> reverse_view in The One Ranges Proposal p0896 <http://wg21.link/p0896> s=
hould=20
>> address that.
>>
>
> Ok. If it can be an elegant one-liner like the following then it's all=20
> good with me:
>
> vector is {0,1,2,3,4};=20
> =20
> for (int i : reverse_view{is})=20
>     cout << i << =E2=80=99 =E2=80=99; // prints: 4 3 2 1 0
>

AFAIK, the exact Ranges syntax (from P0896) is either of the following,=20
which are synonymous:

    for (int i : std::ranges::view::reverse(is)) {
    for (int i : is | std::ranges::view::reverse) {

If all you want is a nice syntax for reverse iteration, and you don't care=
=20
about the other billion lines of the Ranges TS, you can get the nice syntax=
=20
for reverse iteration today in about 5 lines of code.
https://quuxplusone.github.io/blog/2018/08/29/reversed/

HTH,
Arthur

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/26a9d6a3-8170-4442-84fd-6fb4e0058e1c%40isocpp.or=
g.

------=_Part_7_823486325.1535587812832
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, August 28, 2018 at 3:28:50 PM UTC-7, Phil Bouc=
hard 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=
 Tuesday, August 28, 2018 at 5:17:47 PM UTC-4, Nevin &quot;:-)&quot; Liber =
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 Tue, Aug =
28, 2018 at 4:06 PM Phil Bouchard &lt;<a rel=3D"nofollow">phili...@gmail.co=
m</a>&gt; wrote:<br><div class=3D"gmail_quote"><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x">Regarding the for loops with implicit iteration:<br>
<br>
list&lt;string&gt; cars;<br>
<br>
for (auto const &amp; i : cars)<br>
=C2=A0 =C2=A0 ...<br>
<br>
How about reverse iteration for consistency?<br>
<br>
for (auto const &amp; i !: cars)<br>
=C2=A0 =C2=A0 ...<br>
<br>
Or a better syntax.</blockquote><div><br></div><div>reverse_view in The One=
 Ranges Proposal <a href=3D"http://wg21.link/p0896" rel=3D"nofollow" target=
=3D"_blank" onmousedown=3D"this.href=3D&#39;http://www.google.com/url?q\x3d=
http%3A%2F%2Fwg21.link%2Fp0896\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH04u=
m2BjvBbCfTEtSxRU84z5AsQA&#39;;return true;" onclick=3D"this.href=3D&#39;htt=
p://www.google.com/url?q\x3dhttp%3A%2F%2Fwg21.link%2Fp0896\x26sa\x3dD\x26sn=
tz\x3d1\x26usg\x3dAFQjCNH04um2BjvBbCfTEtSxRU84z5AsQA&#39;;return true;">p08=
96</a>=C2=A0should address that.</div></div></div></blockquote><div><br></d=
iv><div>Ok. If it can be an elegant one-liner like the following then it&#3=
9;s all good with me:</div><div><br></div><div>vector is {0,1,2,3,4};=C2=A0=
</div><div>=C2=A0</div><div>for (int i :=C2=A0reverse_view{is})=C2=A0</div>=
<div>=C2=A0 =C2=A0 cout &lt;&lt; i &lt;&lt; =E2=80=99 =E2=80=99; // prints:=
 4 3 2 1 0</div></div></blockquote><div><br></div><div>AFAIK, the exact Ran=
ges syntax (from P0896) is either of the following, which are synonymous:</=
div><div><br></div><div>=C2=A0 =C2=A0 for (int i : std::ranges::view::rever=
se(is)) {</div><div>=C2=A0 =C2=A0 for (int i : is | std::ranges::view::reve=
rse) {</div><div><br></div><div>If all you want is a nice syntax for revers=
e iteration, and you don&#39;t care about the other billion lines of the Ra=
nges TS, you can get the nice syntax for reverse iteration today in about 5=
 lines of code.</div><div><a href=3D"https://quuxplusone.github.io/blog/201=
8/08/29/reversed/">https://quuxplusone.github.io/blog/2018/08/29/reversed/<=
/a><br></div><div><br></div><div>HTH,</div><div>Arthur</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/26a9d6a3-8170-4442-84fd-6fb4e0058e1c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/26a9d6a3-8170-4442-84fd-6fb4e0058e1c=
%40isocpp.org</a>.<br />

------=_Part_7_823486325.1535587812832--

------=_Part_6_1656031552.1535587812832--

.


Author: Andreas Fertig <src@andyf.de>
Date: Fri, 31 Aug 2018 09:32:20 +0200
Raw View
Have a look at Peter Sommerlads work:=20
https://github.com/PeterSommerlad/ReverseAdapter

#include "reverse.h"
#include <iostream>
int main(){
 using ::adapter::reverse;
 for(auto const &i : reverse({0,1,2,3,4,5})) {
         std::cout << i << '\n';
     }
}

--
Andreas


On 2018-08-29 00:28, Phil Bouchard wrote:
> On Tuesday, August 28, 2018 at 5:17:47 PM UTC-4, Nevin ":-)" Liber
> wrote:
>=20
>> On Tue, Aug 28, 2018 at 4:06 PM Phil Bouchard <phili...@gmail.com>
>> wrote:
>>=20
>>> Regarding the for loops with implicit iteration:
>>>=20
>>> list<string> cars;
>>>=20
>>> for (auto const & i : cars)
>>> =C2=A0 =C2=A0 ...
>>>=20
>>> How about reverse iteration for consistency?
>>>=20
>>> for (auto const & i !: cars)
>>> =C2=A0 =C2=A0 ...
>>>=20
>>> Or a better syntax.
>>=20
>> reverse_view in The One Ranges Proposal p0896 [1]=C2=A0should address
>> that.
>=20
> Ok. If it can be an elegant one-liner like the following then it's all
> good with me:
>=20
> vector is {0,1,2,3,4};=C2=A0
> =C2=A0
> for (int i :=C2=A0reverse_view{is})=C2=A0
> =C2=A0 =C2=A0 cout << i << =E2=80=99 =E2=80=99; // prints: 4 3 2 1 0
>=20
> Thanks,
> -Phil
>=20
>  --
>  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.
>  To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5e6ffea4-4c7=
b-4da1-9602-bbd670ce1f8a%40isocpp.org
> [2].
>=20
>=20
> Links:
> ------
> [1] http://wg21.link/p0896
> [2]
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5e6ffea4-4c7=
b-4da1-9602-bbd670ce1f8a%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoote=
r

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/2b61d38aa27b27cdd8d87983ae0d56ed%40example.net.

.