Topic: storage class specifier of range-based for's


Author: Richard Smith <richard@metafoo.co.uk>
Date: Mon, 10 Oct 2016 13:36:08 -0700
Raw View
--001a1144d828bc1d61053e88b5ba
Content-Type: text/plain; charset=UTF-8

On Mon, Oct 10, 2016 at 12:16 PM, <szollosi.lorand@gmail.com> wrote:

> Hi,
>
> Range-based for declares a range and two iterator variables as auto&& and
> auto, respectively. This is unexpected if you declare your loop variable
> static or thread_local.
>

But you can't. [stmt.ranged]/2: "In the decl-specifier-seq of a
for-range-declaration, each decl-specifier shall be either a type-specifier
or constexpr."

It would also be a really strange thing to want to do: the value of the
loop variable would only be initialized by the first iteration of the loop,
the first time the loop is reached (per-thread or per-process).


> This also means that a stackless coroutine cannot yield from and return to
> the middle of the loop - which would be the basic use case for generators.
>

Any reasonable stackless coroutine proposal is able to persist the values
of automatic storage duration variables between suspension and resumption.
That is rather the point of the feature.


> I'd suggest to have the range and the two iterator variables have
> identical storage class specifier as the loop variable (i.e., range
> declaration). This would allow one to switch() / goto into the body of the
> loop.
>

This would still mean that each range-for statement only gets one range for
the entire process/thread.

--
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/CAOfiQqm3ja4Reb_BeXgZ8c1Q%2BA1vTwWmWupiNv6RvQVpAAmVEA%40mail.gmail.com.

--001a1144d828bc1d61053e88b5ba
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Mon, Oct 10, 2016 at 12:16 PM,  <span dir=3D"ltr">&lt;<=
a href=3D"mailto:szollosi.lorand@gmail.com" target=3D"_blank">szollosi.lora=
nd@gmail.com</a>&gt;</span> wrote:<div class=3D"gmail_extra"><div class=3D"=
gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px =
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"=
ltr">Hi,<br><br>Range-based for declares a range and two iterator variables=
 as auto&amp;&amp; and auto, respectively. This is unexpected if you declar=
e your loop variable static or thread_local.</div></blockquote><div><br></d=
iv><div>But you can&#39;t. [stmt.ranged]/2: &quot;In the decl-specifier-seq=
 of a for-range-declaration, each decl-specifier shall be either a type-spe=
cifier or constexpr.&quot;</div><div><br></div><div>It would also be a real=
ly strange thing to want to do: the value of the loop variable would only b=
e initialized by the first iteration of the loop, the first time the loop i=
s reached (per-thread or per-process).</div><div>=C2=A0</div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid=
 rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">This also means that a=
 stackless coroutine cannot yield from and return to the middle of the loop=
 - which would be the basic use case for generators.<br></div></blockquote>=
<div><br></div><div>Any reasonable stackless coroutine proposal is able to =
persist the values of automatic storage duration variables between suspensi=
on and resumption. That is rather the point of the feature.</div><div>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"=
>I&#39;d suggest to have the range and the two iterator variables have iden=
tical storage class specifier as the loop variable (i.e., range declaration=
). This would allow one to switch() / goto into the body of the loop.</div>=
</blockquote><div><br></div><div>This would still mean that each range-for =
statement only gets one range for the entire process/thread.</div></div></d=
iv></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/CAOfiQqm3ja4Reb_BeXgZ8c1Q%2BA1vTwWmWu=
piNv6RvQVpAAmVEA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqm3ja4Reb=
_BeXgZ8c1Q%2BA1vTwWmWupiNv6RvQVpAAmVEA%40mail.gmail.com</a>.<br />

--001a1144d828bc1d61053e88b5ba--

.


Author: szollosi.lorand@gmail.com
Date: Mon, 10 Oct 2016 15:09:10 -0700 (PDT)
Raw View
------=_Part_745_394574104.1476137350935
Content-Type: multipart/alternative;
 boundary="----=_Part_746_1475401679.1476137350935"

------=_Part_746_1475401679.1476137350935
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi,

2016. okt=C3=B3ber 10., h=C3=A9tf=C5=91 22:36:14 UTC+2 id=C5=91pontban Rich=
ard Smith a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> On Mon, Oct 10, 2016 at 12:16 PM, <szollos...@gmail.com <javascript:>>=20
> wrote:
>
>> Hi,
>>
>> Range-based for declares a range and two iterator variables as auto&& an=
d=20
>> auto, respectively. This is unexpected if you declare your loop variable=
=20
>> static or thread_local.
>>
>
> But you can't. [stmt.ranged]/2: "In the decl-specifier-seq of a=20
> for-range-declaration, each decl-specifier shall be either a type-specifi=
er=20
> or constexpr."=20
>
It would also be a really strange thing to want to do: the value of the=20
> loop variable would only be initialized by the first iteration of the loo=
p,=20
> the first time the loop is reached (per-thread or per-process).
>
Yep, that I've missed. A reasonable meaning would be, of course, to declare=
=20
the variable and then reassign (or rather destruct & placement new into)=20
it. Nevertheless, it's not an issue then, sorry for bothering here - it's=
=20
an issue with gcc then (which accepts it and does what you've explained).

This also means that a stackless coroutine cannot yield from and return to=
=20
>> the middle of the loop - which would be the basic use case for generator=
s.
>>
>
> Any reasonable stackless coroutine proposal is able to persist the values=
=20
> of automatic storage duration variables between suspension and resumption=
..=20
> That is rather the point of the feature.=20
>
... but *until* we have that accepted, we use a switch (or switch - goto)=20
and member / static variables.

I'd suggest to have the range and the two iterator variables have identical=
=20
>> storage class specifier as the loop variable (i.e., range declaration).=
=20
>> This would allow one to switch() / goto into the body of the loop.
>>
>
> This would still mean that each range-for statement only gets one range=
=20
> for the entire process/thread.
>
If it's worth considering, one might say that the range gets declared and=
=20
assigned on the first entry; then destructed and placement new'ed into on=
=20
subsequent entries to the for itself. A goto / switch over the for()=20
statement is not considered 'entry'. I'm aware that this is slightly=20
different from what static means, but this can be emulated using a bool=20
flag.

Thanks,
-lorro

--=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/704911f1-95fd-4b7f-8964-2efc2c782e70%40isocpp.or=
g.

------=_Part_746_1475401679.1476137350935
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<br><br>2016. okt=C3=B3ber 10., h=C3=A9tf=C5=91 22:36:1=
4 UTC+2 id=C5=91pontban Richard Smith a k=C3=B6vetkez=C5=91t =C3=ADrta:<blo=
ckquote 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 Mon, Oct 10, 2=
016 at 12:16 PM,  <span dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_=
blank" gdf-obfuscated-mailto=3D"YaxnX0jaAAAJ" rel=3D"nofollow" onmousedown=
=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D=
&#39;javascript:&#39;;return true;">szollos...@gmail.com</a>&gt;</span> wro=
te:<div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex"><div dir=3D"ltr">Hi,<br><br>Range-based for declares a range and=
 two iterator variables as auto&amp;&amp; and auto, respectively. This is u=
nexpected if you declare your loop variable static or thread_local.</div></=
blockquote><div><br></div><div>But you can&#39;t. [stmt.ranged]/2: &quot;In=
 the decl-specifier-seq of a for-range-declaration, each decl-specifier sha=
ll be either a type-specifier or constexpr.&quot; <br></div></div></div></d=
iv></blockquote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r"><div><div class=3D"gmail_quote"><div>It would also be a really strange t=
hing to want to do: the value of the loop variable would only be initialize=
d by the first iteration of the loop, the first time the loop is reached (p=
er-thread or per-process).</div></div></div></div></blockquote><div>Yep, th=
at I&#39;ve missed. A reasonable meaning would be, of course, to declare th=
e variable and then reassign (or rather destruct &amp; placement new into) =
it. Nevertheless, it&#39;s not an issue then, sorry for bothering here - it=
&#39;s an issue with gcc then (which accepts it and does what you&#39;ve ex=
plained).<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div di=
r=3D"ltr"><div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote"=
 style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p=
adding-left:1ex"><div dir=3D"ltr">This also means that a stackless coroutin=
e cannot yield from and return to the middle of the loop - which would be t=
he basic use case for generators.<br></div></blockquote><div><br></div><div=
>Any reasonable stackless coroutine proposal is able to persist the values =
of automatic storage duration variables between suspension and resumption. =
That is rather the point of the feature. <br></div></div></div></div></bloc=
kquote><div>.. but <i>until</i> we have that accepted, we use a switch (or =
switch - goto) and member / static variables.<br><br></div><blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #c=
cc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quot=
e"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bord=
er-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">I&#39=
;d suggest to have the range and the two iterator variables have identical =
storage class specifier as the loop variable (i.e., range declaration). Thi=
s would allow one to switch() / goto into the body of the loop.</div></bloc=
kquote><div><br></div><div>This would still mean that each range-for statem=
ent only gets one range for the entire process/thread.</div></div></div></d=
iv></blockquote><div>If it&#39;s worth considering, one might say that the =
range gets declared and assigned on the first entry; then destructed and pl=
acement new&#39;ed into on subsequent entries to the for itself. A goto / s=
witch over the for() statement is not considered &#39;entry&#39;. I&#39;m a=
ware that this is slightly different from what static means, but this can b=
e emulated using a bool flag.<br><br>Thanks,<br>-lorro<br></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/704911f1-95fd-4b7f-8964-2efc2c782e70%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/704911f1-95fd-4b7f-8964-2efc2c782e70=
%40isocpp.org</a>.<br />

------=_Part_746_1475401679.1476137350935--

------=_Part_745_394574104.1476137350935--

.