Topic: for ... else
Author: "lorro (lorro@lorro.hu)" <szollosi.lorand@gmail.com>
Date: Sun, 17 Jul 2016 07:38:12 -0700 (PDT)
Raw View
------=_Part_186_677953019.1468766292266
Content-Type: multipart/alternative;
boundary="----=_Part_187_728022193.1468766292266"
------=_Part_187_728022193.1468766292266
Content-Type: text/plain; charset=UTF-8
Many cases, specific handling is required when the body of the for loop was
not executed. These include variable initializations which would've gotten
value inside the loop, or throwing exceptions. Currently, these either need
double-checking, which is inefficient, or copying the condition, which is
error-prone, like:
{
*init;*
if(*cond*)
do
{
*body*
incr;
} while(*cond*)
else
*body-not-executed*
}
Note that this is still not exactly what we wanted as variables declared in
init are still visible in else branch. Any alternative requires
double-checking or introducing a boolean variable that's updated in init
and incr. What I'd recommend instead is allowing an else after for:
for(*init*;* cond*; *incr*)
*body*
else
*body-not-executedor,*for(* init *:* range *)
* body*else
*body-not-executed*
As expected, body-not-executed should run iff cond has failed for the first
time (or range was empty); in other words, if body was not executed.
Optimizing compilers can unroll this easily and generate optimal code.
Also, it does not clash with other language features as else is currently
only allowed after an if.
What do you think?
--
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/4c0e87f0-5b39-4922-8028-671fd50361b6%40isocpp.org.
------=_Part_187_728022193.1468766292266
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Many cases, specific handling is required when the body of=
the for loop was not executed. These include variable initializations whic=
h would've gotten value inside the loop, or throwing exceptions. Curren=
tly, these either need double-checking, which is inefficient, or copying th=
e condition, which is error-prone, like:<br><span style=3D"font-family: cou=
rier new,monospace;"><br>{<br>=C2=A0=C2=A0=C2=A0 <i>init;</i><br>=C2=A0=C2=
=A0=C2=A0 if(<i>cond</i>)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 do<=
br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0=C2=A0 <i>body</i><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 incr;<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 } whi=
le(<i>cond</i>)<br>=C2=A0=C2=A0=C2=A0 else<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=
=A0 <i>body-not-executed</i><br>}<br><br><span style=3D"font-family: arial,=
sans-serif;">Note that this is still not exactly what we wanted as variable=
s declared in init are still visible in else branch. Any alternative requir=
es double-checking or introducing a boolean variable that's updated in =
init and incr. What I'd recommend instead is allowing an else after for=
:<br><br><font face=3D"courier new,monospace">for(<i>init</i>;<i> cond</i>;=
<i>incr</i>)<br>=C2=A0=C2=A0=C2=A0 <i>body</i><br>else<br>=C2=A0=C2=A0=C2=
=A0 <i>body-not-executed<br><br><font face=3D"arial,sans-serif">or,<br><br>=
</font></i><font face=3D"arial,sans-serif"><font face=3D"courier new,monosp=
ace">for(</font></font><i><font face=3D"arial,sans-serif"><font face=3D"cou=
rier new,monospace"> init </font></font></i><font face=3D"arial,sans-serif"=
><font face=3D"courier new,monospace">:</font></font><i><font face=3D"arial=
,sans-serif"><font face=3D"courier new,monospace"> range </font></font></i>=
<font face=3D"arial,sans-serif"><font face=3D"courier new,monospace">)</fon=
t></font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,monos=
pace"><br>=C2=A0=C2=A0=C2=A0 body<br></font></font></i><font face=3D"arial,=
sans-serif"><font face=3D"courier new,monospace">else<br>=C2=A0=C2=A0=C2=A0=
<i>body-not-executed</i><br></font></font><i><font face=3D"arial,sans-seri=
f"><font face=3D"courier new,monospace"></font></font><br></i><span style=
=3D"font-family: arial,sans-serif;">As expected, body-not-executed should r=
un iff cond has failed for the first time (or range was empty); in other wo=
rds, if body was not executed. Optimizing compilers can unroll this easily =
and generate optimal code. Also, it does not clash with other language feat=
ures as else is currently only allowed after an if. <br>What do you think?<=
br><font face=3D"courier new,monospace"></font></span></font></span></span>=
</div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4c0e87f0-5b39-4922-8028-671fd50361b6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4c0e87f0-5b39-4922-8028-671fd50361b6=
%40isocpp.org</a>.<br />
------=_Part_187_728022193.1468766292266--
------=_Part_186_677953019.1468766292266--
.
Author: Jared Grubb <jared.grubb@gmail.com>
Date: Sun, 17 Jul 2016 07:49:15 -0700 (PDT)
Raw View
------=_Part_3059_1332615663.1468766955378
Content-Type: multipart/alternative;
boundary="----=_Part_3060_230456279.1468766955385"
------=_Part_3060_230456279.1468766955385
Content-Type: text/plain; charset=UTF-8
On Sunday, July 17, 2016 at 10:38:12 AM UTC-4, lorro (lorro@lorro.hu) wrote:
>
> Many cases, specific handling is required when the body of the for loop
> was not executed. These include variable initializations which would've
> gotten value inside the loop, or throwing exceptions. Currently, these
> either need double-checking, which is inefficient, or copying the
> condition, which is error-prone, like:
>
> {
> *init;*
> if(*cond*)
> do
> {
> *body*
> incr;
> } while(*cond*)
> else
> *body-not-executed*
> }
>
> Note that this is still not exactly what we wanted as variables declared
> in init are still visible in else branch. Any alternative requires
> double-checking or introducing a boolean variable that's updated in init
> and incr. What I'd recommend instead is allowing an else after for:
>
> for(*init*;* cond*; *incr*)
> *body*
> else
>
>
>
>
> *body-not-executedor,*for(* init *:* range *)
>
> * body*else
> *body-not-executed*
>
> As expected, body-not-executed should run iff cond has failed for the
> first time (or range was empty); in other words, if body was not executed.
> Optimizing compilers can unroll this easily and generate optimal code.
> Also, it does not clash with other language features as else is currently
> only allowed after an if.
> What do you think?
>
Python has a construct like what you describe, but the 'else' body is
executed if the range is empty or [the difference] if the range is iterated
to exhaustion; in other words, the 'else' clause is executed unless an
instance of the loop calls 'break'.
I personally really like this construct in Python because it makes some
constructs easier to write. However, it seems that most people find it more
confusing than it's worth and wish it had been named something different.
However, I will point out that your proposal would break existing code; for
example:
if (cond)
for (...) {}
else // does this else match the for or if?
bar();
--
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/fafc85ca-a102-448e-88e3-c7bd0a0af5af%40isocpp.org.
------=_Part_3060_230456279.1468766955385
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, July 17, 2016 at 10:38:12 AM UTC-4, lorro (lorr=
o@lorro.hu) 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">Many cases, specific handling is required when the body of the for loo=
p was not executed. These include variable initializations which would'=
ve gotten value inside the loop, or throwing exceptions. Currently, these e=
ither need double-checking, which is inefficient, or copying the condition,=
which is error-prone, like:<br><span style=3D"font-family:courier new,mono=
space"><br>{<br>=C2=A0=C2=A0=C2=A0 <i>init;</i><br>=C2=A0=C2=A0=C2=A0 if(<i=
>cond</i>)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 do<br>=C2=A0 =C2=
=A0=C2=A0 =C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0=
=C2=A0 <i>body</i><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 incr;<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 } while(<i>cond</=
i>)<br>=C2=A0=C2=A0=C2=A0 else<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body-=
not-executed</i><br>}<br><br><span style=3D"font-family:arial,sans-serif">N=
ote that this is still not exactly what we wanted as variables declared in =
init are still visible in else branch. Any alternative requires double-chec=
king or introducing a boolean variable that's updated in init and incr.=
What I'd recommend instead is allowing an else after for:<br><br><font=
face=3D"courier new,monospace">for(<i>init</i>;<i> cond</i>; <i>incr</i>)<=
br>=C2=A0=C2=A0=C2=A0 <i>body</i><br>else<br>=C2=A0=C2=A0=C2=A0 <i>body-not=
-executed<br><br><font face=3D"arial,sans-serif">or,<br><br></font></i><fon=
t face=3D"arial,sans-serif"><font face=3D"courier new,monospace">for(</font=
></font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,monosp=
ace"> init </font></font></i><font face=3D"arial,sans-serif"><font face=3D"=
courier new,monospace">:</font></font><i><font face=3D"arial,sans-serif"><f=
ont face=3D"courier new,monospace"> range </font></font></i><font face=3D"a=
rial,sans-serif"><font face=3D"courier new,monospace">)</font></font><i><fo=
nt face=3D"arial,sans-serif"><font face=3D"courier new,monospace"><br>=C2=
=A0=C2=A0=C2=A0 body<br></font></font></i><font face=3D"arial,sans-serif"><=
font face=3D"courier new,monospace">else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-=
executed</i><br></font></font><i><font face=3D"arial,sans-serif"><font face=
=3D"courier new,monospace"></font></font><br></i><span style=3D"font-family=
:arial,sans-serif">As expected, body-not-executed should run iff cond has f=
ailed for the first time (or range was empty); in other words, if body was =
not executed. Optimizing compilers can unroll this easily and generate opti=
mal code. Also, it does not clash with other language features as else is c=
urrently only allowed after an if. <br>What do you think?<br></span></font>=
</span></span></div></blockquote><div><br>Python has a construct like what =
you describe, but the 'else' body is executed if the range is empty=
or [the difference] if the range is iterated to exhaustion; in other words=
, the 'else' clause is executed unless an instance of the loop call=
s 'break'.<br><br>I personally really like this construct in Python=
because it makes some constructs easier to write. However, it seems that m=
ost people find it more confusing than it's worth and wish it had been =
named something different.<br><br>However, I will point out that your propo=
sal would break existing code; for example:<br><br>if (cond) <br>=C2=A0 for=
(...) {}<br>else // does this else match the for or if?<br>=C2=A0 bar();<=
br></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/fafc85ca-a102-448e-88e3-c7bd0a0af5af%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/fafc85ca-a102-448e-88e3-c7bd0a0af5af=
%40isocpp.org</a>.<br />
------=_Part_3060_230456279.1468766955385--
------=_Part_3059_1332615663.1468766955378--
.
Author: "D. B." <db0451@gmail.com>
Date: Sun, 17 Jul 2016 15:50:15 +0100
Raw View
--001a114ba3904129a70537d5f8e6
Content-Type: text/plain; charset=UTF-8
If this could possibly exist, it would be nice to have it for *while*, too.
Yes, I know *for* can do the same things as *while*, but for the same
reason, what's one more bit of redundancy going to hurt?
On the converse, it seems that for C++17, while adding arbitrary variable
declarations in *if *and *switch*, for some reason this was skipped for
*while* - perhaps because of the aforesaid redundancy with *for... *and/or
because it might create awkward questions about *do*
Also, great point from Jared. In that case you would need alternate syntax,
such as *for else*. It might get too complicated quickly...
--
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/CACGiwhGN1FH-ocpjUURsmuP37f9O-M1eCbotKCmHLMtD5XNT%3Dg%40mail.gmail.com.
--001a114ba3904129a70537d5f8e6
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>If this could possibly exist, it would be nice to hav=
e it for <b>while</b>, too. Yes, I know <i>for</i> can do the same things a=
s <i>while</i>, but for the same reason, what's one more bit of redunda=
ncy going to hurt?<br><br>On the converse, it seems that for C++17, while a=
dding arbitrary variable declarations in <i>if </i>and <i>switch</i>, for s=
ome reason this was skipped for <i>while</i> - perhaps because of the afore=
said redundancy with <i>for... </i>and/or because it might create awkward q=
uestions about <i>do</i><br><br></div>Also, great point from Jared. In that=
case you would need alternate syntax, such as <i>for else</i>. It might ge=
t too complicated quickly...<br><br></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CACGiwhGN1FH-ocpjUURsmuP37f9O-M1eCbot=
KCmHLMtD5XNT%3Dg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhGN1FH-oc=
pjUURsmuP37f9O-M1eCbotKCmHLMtD5XNT%3Dg%40mail.gmail.com</a>.<br />
--001a114ba3904129a70537d5f8e6--
.
Author: szollosi.lorand@gmail.com
Date: Sun, 17 Jul 2016 09:07:41 -0700 (PDT)
Raw View
------=_Part_251_776571082.1468771661908
Content-Type: multipart/alternative;
boundary="----=_Part_252_336631971.1468771661909"
------=_Part_252_336631971.1468771661909
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Good point - while should also have this.
2016. j=C3=BAlius 17., vas=C3=A1rnap 16:50:18 UTC+2 id=C5=91pontban D. B. a=
k=C3=B6vetkez=C5=91t=20
=C3=ADrta:
>
> If this could possibly exist, it would be nice to have it for *while*,=20
> too. Yes, I know *for* can do the same things as *while*, but for the=20
> same reason, what's one more bit of redundancy going to hurt?
>
> On the converse, it seems that for C++17, while adding arbitrary variable=
=20
> declarations in *if *and *switch*, for some reason this was skipped for=
=20
> *while* - perhaps because of the aforesaid redundancy with *for... *and/o=
r=20
> because it might create awkward questions about *do*
>
> Also, great point from Jared. In that case you would need alternate=20
> syntax, such as *for else*. It might get too complicated quickly...
>
>
--=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/18f3a1b1-426d-4356-923e-15a397842e69%40isocpp.or=
g.
------=_Part_252_336631971.1468771661909
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Good point - while should also have this.<br><br>2016. j=
=C3=BAlius 17., vas=C3=A1rnap 16:50:18 UTC+2 id=C5=91pontban D. B. a k=C3=
=B6vetkez=C5=91t =C3=ADrta:<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"><div>If this could possibly exist, it would be nice to have i=
t for <b>while</b>, too. Yes, I know <i>for</i> can do the same things as <=
i>while</i>, but for the same reason, what's one more bit of redundancy=
going to hurt?<br><br>On the converse, it seems that for C++17, while addi=
ng arbitrary variable declarations in <i>if </i>and <i>switch</i>, for some=
reason this was skipped for <i>while</i> - perhaps because of the aforesai=
d redundancy with <i>for... </i>and/or because it might create awkward ques=
tions about <i>do</i><br><br></div>Also, great point from Jared. In that ca=
se you would need alternate syntax, such as <i>for else</i>. It might get t=
oo complicated quickly...<br><br></div>
</blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/18f3a1b1-426d-4356-923e-15a397842e69%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/18f3a1b1-426d-4356-923e-15a397842e69=
%40isocpp.org</a>.<br />
------=_Part_252_336631971.1468771661909--
------=_Part_251_776571082.1468771661908--
.
Author: szollosi.lorand@gmail.com
Date: Sun, 17 Jul 2016 09:40:26 -0700 (PDT)
Raw View
------=_Part_3392_1449707165.1468773626730
Content-Type: multipart/alternative;
boundary="----=_Part_3393_882063207.1468773626731"
------=_Part_3393_882063207.1468773626731
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
You're perfectly right - in fact, I didn't think about this, sorry.=20
Breaking existing code is a no-go, so we've got three options:
- define a new keyword (elsefor? when?), which is rarely done;
- overload another keyword (catch?), this time using a syntax that=20
allows the compiler to tell the difference between a for-catch and a=20
try-catch;
- specifically resolve this by disallowing for loop having else branch=
=20
when it's the only command in a non-bracketed if. Or, equivalently, havi=
ng=20
if-else more 'vexing' than for-else. This is somewhat more complicated t=
o=20
specify but resolves the ambiguity.
As for the break-based else, it solves a somewhat different issue, but that=
=20
might also be useful. In fact, I like that idea very much (the way we work=
=20
around it, i.e., what it'd save us, is a lambda - let alone function - that=
=20
returns inside the loop and has fallback logic after the loop) - it's far=
=20
from confusing, esp. in C++, when you're used to try-catch blocks. Perhaps=
=20
a 'when(break 0) {}` and `when(0) {}` (or catch similarly) syntax could=20
handle both. This is very similar to exceptions but it's way faster - in=20
fact, given proper compiler support and inlining, it requires no additional=
=20
instructions executed, just the jump addresses changed. In fact, there's no=
=20
reason why we should restrict ourselves to only one of these.
To summarize, we might come up with:
for(*init*;* cond*; *incr*)
*body*
catch(break[0])
*body-no-break-executed*
catch([0])
* body-not-executedand, similarly,*for(* init *:* range *)
* body*catch(break[0])
*body-no-break-executed*
catch([0])
*body-not-executed*
What do you think?
2016. j=C3=BAlius 17., vas=C3=A1rnap 16:49:15 UTC+2 id=C5=91pontban Jared G=
rubb a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> On Sunday, July 17, 2016 at 10:38:12 AM UTC-4, lorro (lo...@lorro.hu=20
> <javascript:>) wrote:
>>
>> Many cases, specific handling is required when the body of the for loop=
=20
>> was not executed. These include variable initializations which would've=
=20
>> gotten value inside the loop, or throwing exceptions. Currently, these=
=20
>> either need double-checking, which is inefficient, or copying the=20
>> condition, which is error-prone, like:
>>
>> {
>> *init;*
>> if(*cond*)
>> do
>> {
>> *body*
>> incr;
>> } while(*cond*)
>> else
>> *body-not-executed*
>> }
>>
>> Note that this is still not exactly what we wanted as variables declared=
=20
>> in init are still visible in else branch. Any alternative requires=20
>> double-checking or introducing a boolean variable that's updated in init=
=20
>> and incr. What I'd recommend instead is allowing an else after for:
>>
>> for(*init*;* cond*; *incr*)
>> *body*
>> else
>> =20
>>
>>
>>
>> *body-not-executedor,*for(* init *:* range *)
>>
>> * body*else
>> *body-not-executed*
>>
>> As expected, body-not-executed should run iff cond has failed for the=20
>> first time (or range was empty); in other words, if body was not execute=
d.=20
>> Optimizing compilers can unroll this easily and generate optimal code.=
=20
>> Also, it does not clash with other language features as else is currentl=
y=20
>> only allowed after an if.=20
>> What do you think?
>>
>
> Python has a construct like what you describe, but the 'else' body is=20
> executed if the range is empty or [the difference] if the range is iterat=
ed=20
> to exhaustion; in other words, the 'else' clause is executed unless an=20
> instance of the loop calls 'break'.
>
> I personally really like this construct in Python because it makes some=
=20
> constructs easier to write. However, it seems that most people find it mo=
re=20
> confusing than it's worth and wish it had been named something different.
>
> However, I will point out that your proposal would break existing code;=
=20
> for example:
>
> if (cond)=20
> for (...) {}
> else // does this else match the for or if?
> bar();
>
--=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/6baa5cbb-e26d-42c5-929c-50c98a716d1a%40isocpp.or=
g.
------=_Part_3393_882063207.1468773626731
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">You're perfectly right - in fact, I didn't think a=
bout this, sorry. Breaking existing code is a no-go, so we've got three=
options:<br><ul><li>define a new keyword (elsefor? when?), which is rarely=
done;</li><li>overload another keyword (catch?), this time using a syntax =
that allows the compiler to tell the difference between a for-catch and a t=
ry-catch;<br></li><li>specifically resolve this by disallowing for loop hav=
ing else branch when it's the only command in a non-bracketed if. Or, e=
quivalently, having if-else more 'vexing' than for-else. This is so=
mewhat more complicated to specify but resolves the ambiguity.</li></ul><p>=
As for the break-based else, it solves a somewhat different issue, but that=
might also be useful. In fact, I like that idea very much (the way we work=
around it, i.e., what it'd save us, is a lambda - let alone function -=
that returns inside the loop and has fallback logic after the loop) - it&#=
39;s far from confusing, esp. in C++, when you're used to try-catch blo=
cks. Perhaps a 'when(break 0) {}` and `when(0) {}` (or catch similarly)=
syntax could handle both. This is very similar to exceptions but it's =
way faster - in fact, given proper compiler support and inlining, it requir=
es no additional instructions executed, just the jump addresses changed. In=
fact, there's no reason why we should restrict ourselves to only one o=
f these.<br></p><br>To summarize, we might come up with:<br><br><span style=
=3D"font-family:courier new,monospace"><span style=3D"font-family:arial,san=
s-serif"><font face=3D"courier new,monospace">for(<i>init</i>;<i> cond</i>;=
<i>incr</i>)<br>=C2=A0=C2=A0=C2=A0 <i>body</i><br>catch(break[0])<br>=C2=
=A0=C2=A0=C2=A0 <i>body-no-break-executed</i></font></span></span><br><span=
style=3D"font-family:courier new,monospace"><span style=3D"font-family:ari=
al,sans-serif"><font face=3D"courier new,monospace"><span style=3D"font-fam=
ily:courier new,monospace"><span style=3D"font-family:arial,sans-serif"><fo=
nt face=3D"courier new,monospace">catch([0])</font></span></span><i><span s=
tyle=3D"font-family:courier new,monospace"><span style=3D"font-family:arial=
,sans-serif"><font face=3D"courier new,monospace"><br>=C2=A0=C2=A0=C2=A0 <i=
>body-not-executed<br><br></i></font></span></span><font face=3D"arial,sans=
-serif">and, similarly,<br><br></font></i><font face=3D"arial,sans-serif"><=
font face=3D"courier new,monospace">for(</font></font><i><font face=3D"aria=
l,sans-serif"><font face=3D"courier new,monospace"> init </font></font></i>=
<font face=3D"arial,sans-serif"><font face=3D"courier new,monospace">:</fon=
t></font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,monos=
pace"> range </font></font></i><font face=3D"arial,sans-serif"><font face=
=3D"courier new,monospace">)</font></font><i><font face=3D"arial,sans-serif=
"><font face=3D"courier new,monospace"><br>=C2=A0=C2=A0=C2=A0 body<br></fon=
t></font></i><font face=3D"arial,sans-serif"><font face=3D"courier new,mono=
space">catch(break[0])<br>=C2=A0=C2=A0=C2=A0 <i>body-no-break-executed</i><=
br>catch([0])<br>=C2=A0=C2=A0=C2=A0 </font></font></font></span></span><spa=
n style=3D"font-family:courier new,monospace"><span style=3D"font-family:ar=
ial,sans-serif"><font face=3D"courier new,monospace"><i><span style=3D"font=
-family:courier new,monospace"><span style=3D"font-family:arial,sans-serif"=
><font face=3D"courier new,monospace"><i>body-not-executed</i></font></span=
></span></i></font></span></span><br><br>What do you think?<br><br>2016. j=
=C3=BAlius 17., vas=C3=A1rnap 16:49:15 UTC+2 id=C5=91pontban Jared Grubb a =
k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote class=3D"gmail_quote" style=3D"m=
argin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"=
><div dir=3D"ltr">On Sunday, July 17, 2016 at 10:38:12 AM UTC-4, lorro (<a =
href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"1mp167I1DAA=
J" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';return=
true;" onclick=3D"this.href=3D'javascript:';return true;">lo...@lo=
rro.hu</a>) wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margi=
n-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
Many cases, specific handling is required when the body of the for loop was=
not executed. These include variable initializations which would've go=
tten value inside the loop, or throwing exceptions. Currently, these either=
need double-checking, which is inefficient, or copying the condition, whic=
h is error-prone, like:<br><span style=3D"font-family:courier new,monospace=
"><br>{<br>=C2=A0=C2=A0=C2=A0 <i>init;</i><br>=C2=A0=C2=A0=C2=A0 if(<i>cond=
</i>)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 do<br>=C2=A0 =C2=A0=C2=
=A0 =C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <=
i>body</i><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 incr;<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 } while(<i>cond</i>)<br>=
=C2=A0=C2=A0=C2=A0 else<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body-not-exe=
cuted</i><br>}<br><br><span style=3D"font-family:arial,sans-serif">Note tha=
t this is still not exactly what we wanted as variables declared in init ar=
e still visible in else branch. Any alternative requires double-checking or=
introducing a boolean variable that's updated in init and incr. What I=
'd recommend instead is allowing an else after for:<br><br><font face=
=3D"courier new,monospace">for(<i>init</i>;<i> cond</i>; <i>incr</i>)<br>=
=C2=A0=C2=A0=C2=A0 <i>body</i><br>else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-ex=
ecuted<br><br><font face=3D"arial,sans-serif">or,<br><br></font></i><font f=
ace=3D"arial,sans-serif"><font face=3D"courier new,monospace">for(</font></=
font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospace=
"> init </font></font></i><font face=3D"arial,sans-serif"><font face=3D"cou=
rier new,monospace">:</font></font><i><font face=3D"arial,sans-serif"><font=
face=3D"courier new,monospace"> range </font></font></i><font face=3D"aria=
l,sans-serif"><font face=3D"courier new,monospace">)</font></font><i><font =
face=3D"arial,sans-serif"><font face=3D"courier new,monospace"><br>=C2=A0=
=C2=A0=C2=A0 body<br></font></font></i><font face=3D"arial,sans-serif"><fon=
t face=3D"courier new,monospace">else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-exe=
cuted</i><br></font></font><i><font face=3D"arial,sans-serif"><font face=3D=
"courier new,monospace"></font></font><br></i><span style=3D"font-family:ar=
ial,sans-serif">As expected, body-not-executed should run iff cond has fail=
ed for the first time (or range was empty); in other words, if body was not=
executed. Optimizing compilers can unroll this easily and generate optimal=
code. Also, it does not clash with other language features as else is curr=
ently only allowed after an if. <br>What do you think?<br></span></font></s=
pan></span></div></blockquote><div><br>Python has a construct like what you=
describe, but the 'else' body is executed if the range is empty or=
[the difference] if the range is iterated to exhaustion; in other words, t=
he 'else' clause is executed unless an instance of the loop calls &=
#39;break'.<br><br>I personally really like this construct in Python be=
cause it makes some constructs easier to write. However, it seems that most=
people find it more confusing than it's worth and wish it had been nam=
ed something different.<br><br>However, I will point out that your proposal=
would break existing code; for example:<br><br>if (cond) <br>=C2=A0 for (.=
...) {}<br>else // does this else match the for or if?<br>=C2=A0 bar();<br>=
</div></div></blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/6baa5cbb-e26d-42c5-929c-50c98a716d1a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6baa5cbb-e26d-42c5-929c-50c98a716d1a=
%40isocpp.org</a>.<br />
------=_Part_3393_882063207.1468773626731--
------=_Part_3392_1449707165.1468773626730--
.
Author: "D. B." <db0451@gmail.com>
Date: Sun, 17 Jul 2016 18:02:50 +0100
Raw View
--001a114b703a6d3c8f0537d7d25b
Content-Type: text/plain; charset=UTF-8
I think using *catch* here is a terrible idea given its current semantics,
and probably not grammatically viable anyway. Insisting on that keyword is
liable to sink this proposal before it could ever get anywhere.
Why not just *for (...) { /* things if condition == true */ } for else { /*
things if condition == false */ }*
--
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/CACGiwhGKv4aNgsNb9%3DOxJYU%3D-4LGwQeFxJ-6N5saezyUPRovyQ%40mail.gmail.com.
--001a114b703a6d3c8f0537d7d25b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I think using <i>catch</i> here is a terrible idea gi=
ven its current semantics, and probably not grammatically viable anyway. In=
sisting on that keyword is liable to sink this proposal before it could eve=
r get anywhere.<br><br></div>Why not just <i>for (...) { /* things if condi=
tion =3D=3D true */ } for else { /* things if condition =3D=3D false */ }</=
i><br></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CACGiwhGKv4aNgsNb9%3DOxJYU%3D-4LGwQeF=
xJ-6N5saezyUPRovyQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhGKv4aN=
gsNb9%3DOxJYU%3D-4LGwQeFxJ-6N5saezyUPRovyQ%40mail.gmail.com</a>.<br />
--001a114b703a6d3c8f0537d7d25b--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 17 Jul 2016 20:03:11 +0300
Raw View
On 17 July 2016 at 17:38, lorro (lorro@lorro.hu)
<szollosi.lorand@gmail.com> wrote:
> Many cases, specific handling is required when the body of the for loop was
> not executed. These include variable initializations which would've gotten
See http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0082r1.pdf
That paper didn't gain consensus in Jacksonville. Different approaches
might come up for C++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/CAFk2RUbwY1Q1Ddjtodz3%2BVHa-hZzYN-5GZHYX%3Dah%2Brrvbg1MHA%40mail.gmail.com.
.
Author: szollosi.lorand@gmail.com
Date: Sun, 17 Jul 2016 10:04:57 -0700 (PDT)
Raw View
------=_Part_112_464747088.1468775098037
Content-Type: multipart/alternative;
boundary="----=_Part_113_1449075660.1468775098038"
------=_Part_113_1449075660.1468775098038
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Merging with D. B.'s recommendations:
To summarize, we might come up with:
for(*init*;* cond*; *incr*)
*body*
catch(break[0])
*body-no-break-executed*
catch([0])
* body-not-executed*for(* init *:* range *)
* body*catch(break[0])
*body-no-break-executed*
catch([0])
=20
*body-not-executed*
while(*cond*)
*body*
catch(break[0])
*body-no-break-executed*
catch([0])
* body-not-executed*
2016. j=C3=BAlius 17., vas=C3=A1rnap 18:40:27 UTC+2 id=C5=91pontban szollos=
....@gmail.com a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> You're perfectly right - in fact, I didn't think about this, sorry.=20
> Breaking existing code is a no-go, so we've got three options:
>
> - define a new keyword (elsefor? when?), which is rarely done;
> - overload another keyword (catch?), this time using a syntax that=20
> allows the compiler to tell the difference between a for-catch and a=
=20
> try-catch;
> - specifically resolve this by disallowing for loop having else branch=
=20
> when it's the only command in a non-bracketed if. Or, equivalently, ha=
ving=20
> if-else more 'vexing' than for-else. This is somewhat more complicated=
to=20
> specify but resolves the ambiguity.
>
> As for the break-based else, it solves a somewhat different issue, but=20
> that might also be useful. In fact, I like that idea very much (the way w=
e=20
> work around it, i.e., what it'd save us, is a lambda - let alone function=
-=20
> that returns inside the loop and has fallback logic after the loop) - it'=
s=20
> far from confusing, esp. in C++, when you're used to try-catch blocks.=20
> Perhaps a 'when(break 0) {}` and `when(0) {}` (or catch similarly) syntax=
=20
> could handle both. This is very similar to exceptions but it's way faster=
-=20
> in fact, given proper compiler support and inlining, it requires no=20
> additional instructions executed, just the jump addresses changed. In fac=
t,=20
> there's no reason why we should restrict ourselves to only one of these.
>
> To summarize, we might come up with:
>
> for(*init*;* cond*; *incr*)
> *body*
> catch(break[0])
> *body-no-break-executed*
> catch([0])
>
>
>
>
> * body-not-executedand, similarly,*for(* init *:* range *)
>
> * body*catch(break[0])
> *body-no-break-executed*
> catch([0])
> *body-not-executed*
>
> What do you think?
>
> 2016. j=C3=BAlius 17., vas=C3=A1rnap 16:49:15 UTC+2 id=C5=91pontban Jared=
Grubb a=20
> k=C3=B6vetkez=C5=91t =C3=ADrta:
>>
>> On Sunday, July 17, 2016 at 10:38:12 AM UTC-4, lorro (lo...@lorro.hu)=20
>> wrote:
>>>
>>> Many cases, specific handling is required when the body of the for loop=
=20
>>> was not executed. These include variable initializations which would've=
=20
>>> gotten value inside the loop, or throwing exceptions. Currently, these=
=20
>>> either need double-checking, which is inefficient, or copying the=20
>>> condition, which is error-prone, like:
>>>
>>> {
>>> *init;*
>>> if(*cond*)
>>> do
>>> {
>>> *body*
>>> incr;
>>> } while(*cond*)
>>> else
>>> *body-not-executed*
>>> }
>>>
>>> Note that this is still not exactly what we wanted as variables declare=
d=20
>>> in init are still visible in else branch. Any alternative requires=20
>>> double-checking or introducing a boolean variable that's updated in ini=
t=20
>>> and incr. What I'd recommend instead is allowing an else after for:
>>>
>>> for(*init*;* cond*; *incr*)
>>> *body*
>>> else
>>> =20
>>>
>>>
>>>
>>> *body-not-executedor,*for(* init *:* range *)
>>>
>>> * body*else
>>> *body-not-executed*
>>>
>>> As expected, body-not-executed should run iff cond has failed for the=
=20
>>> first time (or range was empty); in other words, if body was not execut=
ed.=20
>>> Optimizing compilers can unroll this easily and generate optimal code.=
=20
>>> Also, it does not clash with other language features as else is current=
ly=20
>>> only allowed after an if.=20
>>> What do you think?
>>>
>>
>> Python has a construct like what you describe, but the 'else' body is=20
>> executed if the range is empty or [the difference] if the range is itera=
ted=20
>> to exhaustion; in other words, the 'else' clause is executed unless an=
=20
>> instance of the loop calls 'break'.
>>
>> I personally really like this construct in Python because it makes some=
=20
>> constructs easier to write. However, it seems that most people find it m=
ore=20
>> confusing than it's worth and wish it had been named something different=
..
>>
>> However, I will point out that your proposal would break existing code;=
=20
>> for example:
>>
>> if (cond)=20
>> for (...) {}
>> else // does this else match the for or if?
>> bar();
>>
>
--=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/c6f907b0-c25a-4494-bf9a-08416890f8af%40isocpp.or=
g.
------=_Part_113_1449075660.1468775098038
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Merging with D. B.'s recommendations:<br><br>To summar=
ize, we might come up with:<br><br><span style=3D"font-family:courier new,m=
onospace"><span style=3D"font-family:arial,sans-serif"><font face=3D"courie=
r new,monospace">for(<i>init</i>;<i> cond</i>; <i>incr</i>)<br>=C2=A0=C2=A0=
=C2=A0 <i>body</i><br>catch(break[0])<br>=C2=A0=C2=A0=C2=A0 <i>body-no-brea=
k-executed</i></font></span></span><br><span style=3D"font-family:courier n=
ew,monospace"><span style=3D"font-family:arial,sans-serif"><font face=3D"co=
urier new,monospace"><span style=3D"font-family:courier new,monospace"><spa=
n style=3D"font-family:arial,sans-serif"><font face=3D"courier new,monospac=
e">catch([0])</font></span></span><i><span style=3D"font-family:courier new=
,monospace"><span style=3D"font-family:arial,sans-serif"><font face=3D"cour=
ier new,monospace"><br>=C2=A0=C2=A0=C2=A0 <i>body-not-executed<br><br></i><=
/font></span></span></i><font face=3D"arial,sans-serif"><font face=3D"couri=
er new,monospace">for(</font></font><i><font face=3D"arial,sans-serif"><fon=
t face=3D"courier new,monospace"> init </font></font></i><font face=3D"aria=
l,sans-serif"><font face=3D"courier new,monospace">:</font></font><i><font =
face=3D"arial,sans-serif"><font face=3D"courier new,monospace"> range </fon=
t></font></i><font face=3D"arial,sans-serif"><font face=3D"courier new,mono=
space">)</font></font><i><font face=3D"arial,sans-serif"><font face=3D"cour=
ier new,monospace"><br>=C2=A0=C2=A0=C2=A0 body<br></font></font></i><font f=
ace=3D"arial,sans-serif"><font face=3D"courier new,monospace">catch(break[0=
])<br>=C2=A0=C2=A0=C2=A0 <i>body-no-break-executed</i><br>catch([0])<br>=C2=
=A0=C2=A0=C2=A0 </font></font></font></span></span><span style=3D"font-fami=
ly:courier new,monospace"><span style=3D"font-family:arial,sans-serif"><fon=
t face=3D"courier new,monospace"><i><span style=3D"font-family:courier new,=
monospace"><span style=3D"font-family:arial,sans-serif"><font face=3D"couri=
er new,monospace"><i>body-not-executed<br></i></font></span></span></i></fo=
nt></span></span><br><span style=3D"font-family:courier new,monospace"><spa=
n style=3D"font-family:arial,sans-serif"><font face=3D"courier new,monospac=
e">while(<i>cond</i><i></i>)<br>=C2=A0=C2=A0=C2=A0 <i>body</i><br>catch(bre=
ak[0])<br>=C2=A0=C2=A0=C2=A0 <i>body-no-break-executed</i></font></span></s=
pan><br><span style=3D"font-family:courier new,monospace"><span style=3D"fo=
nt-family:arial,sans-serif"><font face=3D"courier new,monospace"><span styl=
e=3D"font-family:courier new,monospace"><span style=3D"font-family:arial,sa=
ns-serif"><font face=3D"courier new,monospace">catch([0])</font></span></sp=
an><i><span style=3D"font-family:courier new,monospace"><span style=3D"font=
-family:arial,sans-serif"><font face=3D"courier new,monospace"><br>=C2=A0=
=C2=A0=C2=A0 <i>body-not-executed</i></font></span></span><font face=3D"ari=
al,sans-serif"><br></font></i></font></span></span><br>2016. j=C3=BAlius 17=
.., vas=C3=A1rnap 18:40:27 UTC+2 id=C5=91pontban szollos...@gmail.com a k=C3=
=B6vetkez=C5=91t =C3=ADrta:<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">You're perfectly right - in fact, I didn't think abou=
t this, sorry. Breaking existing code is a no-go, so we've got three op=
tions:<br><ul><li>define a new keyword (elsefor? when?), which is rarely do=
ne;</li><li>overload another keyword (catch?), this time using a syntax tha=
t allows the compiler to tell the difference between a for-catch and a try-=
catch;<br></li><li>specifically resolve this by disallowing for loop having=
else branch when it's the only command in a non-bracketed if. Or, equi=
valently, having if-else more 'vexing' than for-else. This is somew=
hat more complicated to specify but resolves the ambiguity.</li></ul><p>As =
for the break-based else, it solves a somewhat different issue, but that mi=
ght also be useful. In fact, I like that idea very much (the way we work ar=
ound it, i.e., what it'd save us, is a lambda - let alone function - th=
at returns inside the loop and has fallback logic after the loop) - it'=
s far from confusing, esp. in C++, when you're used to try-catch blocks=
.. Perhaps a 'when(break 0) {}` and `when(0) {}` (or catch similarly) sy=
ntax could handle both. This is very similar to exceptions but it's way=
faster - in fact, given proper compiler support and inlining, it requires =
no additional instructions executed, just the jump addresses changed. In fa=
ct, there's no reason why we should restrict ourselves to only one of t=
hese.<br></p><br>To summarize, we might come up with:<br><br><span style=3D=
"font-family:courier new,monospace"><span style=3D"font-family:arial,sans-s=
erif"><font face=3D"courier new,monospace">for(<i>init</i>;<i> cond</i>; <i=
>incr</i>)<br>=C2=A0=C2=A0=C2=A0 <i>body</i><br>catch(break[0])<br>=C2=A0=
=C2=A0=C2=A0 <i>body-no-break-executed</i></font></span></span><br><span st=
yle=3D"font-family:courier new,monospace"><span style=3D"font-family:arial,=
sans-serif"><font face=3D"courier new,monospace"><span style=3D"font-family=
:courier new,monospace"><span style=3D"font-family:arial,sans-serif"><font =
face=3D"courier new,monospace">catch([0])</font></span></span><i><span styl=
e=3D"font-family:courier new,monospace"><span style=3D"font-family:arial,sa=
ns-serif"><font face=3D"courier new,monospace"><br>=C2=A0=C2=A0=C2=A0 <i>bo=
dy-not-executed<br><br></i></font></span></span><font face=3D"arial,sans-se=
rif">and, similarly,<br><br></font></i><font face=3D"arial,sans-serif"><fon=
t face=3D"courier new,monospace">for(</font></font><i><font face=3D"arial,s=
ans-serif"><font face=3D"courier new,monospace"> init </font></font></i><fo=
nt face=3D"arial,sans-serif"><font face=3D"courier new,monospace">:</font><=
/font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospac=
e"> range </font></font></i><font face=3D"arial,sans-serif"><font face=3D"c=
ourier new,monospace">)</font></font><i><font face=3D"arial,sans-serif"><fo=
nt face=3D"courier new,monospace"><br>=C2=A0=C2=A0=C2=A0 body<br></font></f=
ont></i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospace=
">catch(break[0])<br>=C2=A0=C2=A0=C2=A0 <i>body-no-break-executed</i><br>ca=
tch([0])<br>=C2=A0=C2=A0=C2=A0 </font></font></font></span></span><span sty=
le=3D"font-family:courier new,monospace"><span style=3D"font-family:arial,s=
ans-serif"><font face=3D"courier new,monospace"><i><span style=3D"font-fami=
ly:courier new,monospace"><span style=3D"font-family:arial,sans-serif"><fon=
t face=3D"courier new,monospace"><i>body-not-executed</i></font></span></sp=
an></i></font></span></span><br><br>What do you think?<br><br>2016. j=C3=BA=
lius 17., vas=C3=A1rnap 16:49:15 UTC+2 id=C5=91pontban Jared Grubb a k=C3=
=B6vetkez=C5=91t =C3=ADrta:<blockquote class=3D"gmail_quote" style=3D"margi=
n:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr">On Sunday, July 17, 2016 at 10:38:12 AM UTC-4, lorro (<a rel=3D"no=
follow">lo...@lorro.hu</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">Many cases, specific handling is required when the body o=
f the for loop was not executed. These include variable initializations whi=
ch would've gotten value inside the loop, or throwing exceptions. Curre=
ntly, these either need double-checking, which is inefficient, or copying t=
he condition, which is error-prone, like:<br><span style=3D"font-family:cou=
rier new,monospace"><br>{<br>=C2=A0=C2=A0=C2=A0 <i>init;</i><br>=C2=A0=C2=
=A0=C2=A0 if(<i>cond</i>)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 do<=
br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0=C2=A0 <i>body</i><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 incr;<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 } whi=
le(<i>cond</i>)<br>=C2=A0=C2=A0=C2=A0 else<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=
=A0 <i>body-not-executed</i><br>}<br><br><span style=3D"font-family:arial,s=
ans-serif">Note that this is still not exactly what we wanted as variables =
declared in init are still visible in else branch. Any alternative requires=
double-checking or introducing a boolean variable that's updated in in=
it and incr. What I'd recommend instead is allowing an else after for:<=
br><br><font face=3D"courier new,monospace">for(<i>init</i>;<i> cond</i>; <=
i>incr</i>)<br>=C2=A0=C2=A0=C2=A0 <i>body</i><br>else<br>=C2=A0=C2=A0=C2=A0=
<i>body-not-executed<br><br><font face=3D"arial,sans-serif">or,<br><br></f=
ont></i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospace=
">for(</font></font><i><font face=3D"arial,sans-serif"><font face=3D"courie=
r new,monospace"> init </font></font></i><font face=3D"arial,sans-serif"><f=
ont face=3D"courier new,monospace">:</font></font><i><font face=3D"arial,sa=
ns-serif"><font face=3D"courier new,monospace"> range </font></font></i><fo=
nt face=3D"arial,sans-serif"><font face=3D"courier new,monospace">)</font><=
/font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospac=
e"><br>=C2=A0=C2=A0=C2=A0 body<br></font></font></i><font face=3D"arial,san=
s-serif"><font face=3D"courier new,monospace">else<br>=C2=A0=C2=A0=C2=A0 <i=
>body-not-executed</i><br></font></font><i><font face=3D"arial,sans-serif">=
<font face=3D"courier new,monospace"></font></font><br></i><span style=3D"f=
ont-family:arial,sans-serif">As expected, body-not-executed should run iff =
cond has failed for the first time (or range was empty); in other words, if=
body was not executed. Optimizing compilers can unroll this easily and gen=
erate optimal code. Also, it does not clash with other language features as=
else is currently only allowed after an if. <br>What do you think?<br></sp=
an></font></span></span></div></blockquote><div><br>Python has a construct =
like what you describe, but the 'else' body is executed if the rang=
e is empty or [the difference] if the range is iterated to exhaustion; in o=
ther words, the 'else' clause is executed unless an instance of the=
loop calls 'break'.<br><br>I personally really like this construct=
in Python because it makes some constructs easier to write. However, it se=
ems that most people find it more confusing than it's worth and wish it=
had been named something different.<br><br>However, I will point out that =
your proposal would break existing code; for example:<br><br>if (cond) <br>=
=C2=A0 for (...) {}<br>else // does this else match the for or if?<br>=C2=
=A0 bar();<br></div></div></blockquote></div></blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/c6f907b0-c25a-4494-bf9a-08416890f8af%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c6f907b0-c25a-4494-bf9a-08416890f8af=
%40isocpp.org</a>.<br />
------=_Part_113_1449075660.1468775098038--
------=_Part_112_464747088.1468775098037--
.
Author: "D. B." <db0451@gmail.com>
Date: Sun, 17 Jul 2016 18:14:13 +0100
Raw View
--001a113d7b2e1af2cb0537d7fb4d
Content-Type: text/plain; charset=UTF-8
On Sun, Jul 17, 2016 at 6:03 PM, Ville Voutilainen <
ville.voutilainen@gmail.com> wrote:
> On 17 July 2016 at 17:38, lorro (lorro@lorro.hu)
> <szollosi.lorand@gmail.com> wrote:
> > Many cases, specific handling is required when the body of the for loop
> was
> > not executed. These include variable initializations which would've
> gotten
>
> See http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0082r1.pdf
>
> That paper didn't gain consensus in Jacksonville. Different approaches
> might come up for C++20.
>
I do like these, but I find it odd that *catch* seems to be people's
default keyword. Out of interest - is the general reaction to seeing *catch*
used in a non-exception scenario as averse as my own? Heh.
--
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/CACGiwhHD0-Lroo7sZCL2Y0mNM4QkgQbf9fGD1NcGOUGZwcxMug%40mail.gmail.com.
--001a113d7b2e1af2cb0537d7fb4d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On Sun, Jul 17, 2016 at 6:03 PM, Ville Voutilainen <span dir=3D"ltr"><<a=
href=3D"mailto:ville.voutilainen@gmail.com" target=3D"_blank">ville.voutil=
ainen@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On =
17 July 2016 at 17:38, lorro (<a href=3D"mailto:lorro@lorro.hu">lorro@lorro=
..hu</a>)<br>
<span class=3D""><<a href=3D"mailto:szollosi.lorand@gmail.com">szollosi.=
lorand@gmail.com</a>> wrote:<br>
> Many cases, specific handling is required when the body of the for loo=
p was<br>
> not executed. These include variable initializations which would'v=
e gotten<br>
<br>
</span>See <a href=3D"http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p=
0082r1.pdf" rel=3D"noreferrer" target=3D"_blank">http://open-std.org/JTC1/S=
C22/WG21/docs/papers/2016/p0082r1.pdf</a><br>
<br>
That paper didn't gain consensus in Jacksonville. Different approaches<=
br>
might come up for C++20.<span class=3D""><br></span></blockquote><div><br><=
br></div><div>I do like these, but I find it odd that <i>catch</i> seems to=
be people's default keyword. Out of interest - is the general reaction=
to seeing <i>catch</i> used in a non-exception scenario as averse as my ow=
n? Heh.<br><br></div></div><br></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CACGiwhHD0-Lroo7sZCL2Y0mNM4QkgQbf9fGD=
1NcGOUGZwcxMug%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhHD0-Lroo7s=
ZCL2Y0mNM4QkgQbf9fGD1NcGOUGZwcxMug%40mail.gmail.com</a>.<br />
--001a113d7b2e1af2cb0537d7fb4d--
.
Author: Tony V E <tvaneerd@gmail.com>
Date: Sun, 17 Jul 2016 13:19:32 -0400
Raw View
<html><head></head><body lang=3D"en-US" style=3D"background-color: rgb(255,=
255, 255); line-height: initial;"> =
<div style=3D"width: 100%; fo=
nt-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif=
; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, =
255, 255);">I have my doubts about whether the proposal is useful enough to=
spend time on,</div><div style=3D"width: 100%; font-size: initial; font-fa=
mily: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125)=
; text-align: initial; background-color: rgb(255, 255, 255);">But I like 'f=
or else' better than catch. </div><div style=3D"width: 100%; font-size=
: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color=
: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 25=
5);"><br></div><div style=3D"width: 100%; font-size: initial; font-family: =
Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text=
-align: initial; background-color: rgb(255, 255, 255);">But even better wou=
ld be 'or else'=E2=80=8E :-)</div><div style=3D"width: 100%; font-size: ini=
tial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb=
(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">=
<br></div> =
<div st=
yle=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', =
sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; backg=
round-color: rgb(255, 255, 255);"><br style=3D"display:initial"></div> =
=
=
<div style=3D"font-size: initial; f=
ont-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73=
, 125); text-align: initial; background-color: rgb(255, 255, 255);">Sent&nb=
sp;from my BlackBerry portable Babbage Device</div=
> =
=
<table width=3D"100%" style=3D"background-colo=
r:white;border-spacing:0px;"> <tbody><tr><td colspan=3D"2" style=3D"font-si=
ze: initial; text-align: initial; background-color: rgb(255, 255, 255);"> =
<div style=3D"border-style: solid none none; borde=
r-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0in 0i=
n; font-family: Tahoma, 'BB Alpha Sans', 'Slate Pro'; font-size: 10pt;"> <=
div><b>From: </b>D. B.</div><div><b>Sent: </b>Sunday, July 17, 2016 1:02 PM=
</div><div><b>To: </b>std-proposals@isocpp.org</div><div><b>Reply To: </b>s=
td-proposals@isocpp.org</div><div><b>Subject: </b>Re: [std-proposals] Re: f=
or ... else</div></div></td></tr></tbody></table><div style=3D"border-style=
: solid none none; border-top-color: rgb(186, 188, 209); border-top-width: =
1pt; font-size: initial; text-align: initial; background-color: rgb(255, 25=
5, 255);"></div><br><div id=3D"_originalContent" style=3D""><div dir=3D"ltr=
"><div>I think using <i>catch</i> here is a terrible idea given its current=
semantics, and probably not grammatically viable anyway. Insisting on that=
keyword is liable to sink this proposal before it could ever get anywhere.=
<br><br></div>Why not just <i>for (...) { /* things if condition =3D=3D tru=
e */ } for else { /* things if condition =3D=3D false */ }</i><br></div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups "=
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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CACGiwhGKv4aNgsNb9%3DOxJYU%3D-4LGwQeF=
xJ-6N5saezyUPRovyQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoo=
ter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhGK=
v4aNgsNb9%3DOxJYU%3D-4LGwQeFxJ-6N5saezyUPRovyQ%40mail.gmail.com</a>.<br>
<br><!--end of _originalContent --></div></body></html>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/20160717171932.4882510.5686.14246%40g=
mail.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/20160717171932.4882510.5686.14246%40gmai=
l.com</a>.<br />
.
Author: "D. B." <db0451@gmail.com>
Date: Sun, 17 Jul 2016 18:24:22 +0100
Raw View
--001a1148f8da6b07740537d81f76
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Sun, Jul 17, 2016 at 6:19 PM, Tony V E <tvaneerd@gmail.com> wrote:
> I have my doubts about whether the proposal is useful enough to spend tim=
e
> on,
> But I like 'for else' better than catch.
>
> But even better would be 'or else'=E2=80=8E :-)
>
I dunno, it does touch on break-out cases whose verbosity has annoyed me in
the past - while being nowhere near the complexity of some examples in that
paper - and it looks very logical, chosen labels notwithstanding.
"or else" is funny, but I think for ultimate clarity, it should be "xor
else" ;-)
--=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/CACGiwhEnb7vdGkByVdc%2BqC5c5ECKLbx%3D6CAz1ndsa%3=
DVNFn_qRA%40mail.gmail.com.
--001a1148f8da6b07740537d81f76
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
un, Jul 17, 2016 at 6:19 PM, Tony V E <span dir=3D"ltr"><<a href=3D"mail=
to:tvaneerd@gmail.com" target=3D"_blank">tvaneerd@gmail.com</a>></span> =
wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8=
ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style=3D"b=
ackground-color:rgb(255,255,255);line-height:initial" lang=3D"en-US"> =
=
<div style=3D"width:100%;font-size:initial;font-family:Calibri,"S=
late Pro",sans-serif,sans-serif;color:rgb(31,73,125);text-align:initia=
l;background-color:rgb(255,255,255)">I have my doubts about whether the pro=
posal is useful enough to spend time on,</div><div style=3D"width:100%;font=
-size:initial;font-family:Calibri,"Slate Pro",sans-serif,sans-ser=
if;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255=
)">But I like 'for else' better than catch.=C2=A0</div><div style=
=3D"width:100%;font-size:initial;font-family:Calibri,"Slate Pro",=
sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-co=
lor:rgb(255,255,255)"><br></div><div style=3D"width:100%;font-size:initial;=
font-family:Calibri,"Slate Pro",sans-serif,sans-serif;color:rgb(3=
1,73,125);text-align:initial;background-color:rgb(255,255,255)">But even be=
tter would be 'or else'=E2=80=8E :-)</div></div></blockquote><div><=
br>I dunno, it does touch on break-out cases whose verbosity has annoyed me=
in the past - while being nowhere near the complexity of some examples in =
that paper - and=20
it looks very logical, chosen labels notwithstanding.<br><br>"or else&=
quot; is=20
funny, but I think for ultimate clarity, it should be "xor else" =
;-) <br></div></div><br><br></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CACGiwhEnb7vdGkByVdc%2BqC5c5ECKLbx%3D=
6CAz1ndsa%3DVNFn_qRA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhEnb7=
vdGkByVdc%2BqC5c5ECKLbx%3D6CAz1ndsa%3DVNFn_qRA%40mail.gmail.com</a>.<br />
--001a1148f8da6b07740537d81f76--
.
Author: szollosi.lorand@gmail.com
Date: Sun, 17 Jul 2016 10:24:48 -0700 (PDT)
Raw View
------=_Part_3516_1587850880.1468776288916
Content-Type: multipart/alternative;
boundary="----=_Part_3517_890152290.1468776288916"
------=_Part_3517_890152290.1468776288916
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Actual syntax is not that important to me. For me, *for(...) { ... } for=20
break { ... } for else { ... } *is perfectly fine, same for *while*.
2016. j=C3=BAlius 17., vas=C3=A1rnap 19:02:53 UTC+2 id=C5=91pontban D. B. a=
k=C3=B6vetkez=C5=91t=20
=C3=ADrta:
>
> I think using *catch* here is a terrible idea given its current=20
> semantics, and probably not grammatically viable anyway. Insisting on tha=
t=20
> keyword is liable to sink this proposal before it could ever get anywhere=
..
>
> Why not just *for (...) { /* things if condition =3D=3D true */ } for els=
e {=20
> /* things if condition =3D=3D false */ }*
>
--=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/257f52d0-2418-42bc-8010-1b2b656f0897%40isocpp.or=
g.
------=_Part_3517_890152290.1468776288916
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Actual syntax is not that important to me. For me, <i>for(=
....) { ... } for break { ... } for else { ... } </i>is perfectly fine, same=
for <i>while</i>.<br><br>2016. j=C3=BAlius 17., vas=C3=A1rnap 19:02:53 UTC=
+2 id=C5=91pontban D. B. a k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr"><div>I think using <i>catch</i=
> here is a terrible idea given its current semantics, and probably not gra=
mmatically viable anyway. Insisting on that keyword is liable to sink this =
proposal before it could ever get anywhere.<br><br></div>Why not just <i>fo=
r (...) { /* things if condition =3D=3D true */ } for else { /* things if c=
ondition =3D=3D false */ }</i><br></div>
</blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/257f52d0-2418-42bc-8010-1b2b656f0897%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/257f52d0-2418-42bc-8010-1b2b656f0897=
%40isocpp.org</a>.<br />
------=_Part_3517_890152290.1468776288916--
------=_Part_3516_1587850880.1468776288916--
.
Author: "D. B." <db0451@gmail.com>
Date: Sun, 17 Jul 2016 18:30:02 +0100
Raw View
--001a113d7b2eac8bf30537d83306
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Sun, Jul 17, 2016 at 6:24 PM, <szollosi.lorand@gmail.com> wrote:
> Actual syntax is not that important to me. For me, *for(...) { ... } for
> break { ... } for else { ... } *is perfectly fine, same for *while*.
>
> 2016. j=C3=BAlius 17., vas=C3=A1rnap 19:02:53 UTC+2 id=C5=91pontban D. B.=
a k=C3=B6vetkez=C5=91t
> =C3=ADrta:
>>
>> I think using *catch* here is a terrible idea given its current
>> semantics, and probably not grammatically viable anyway. Insisting on th=
at
>> keyword is liable to sink this proposal before it could ever get anywher=
e.
>>
>> Why not just *for (...) { /* things if condition =3D=3D true */ } for el=
se {
>> /* things if condition =3D=3D false */ }*
>>
>
Yeah, *{for/while} {break/else}* definitely get my vote for the moment.
Btw, would you want this to apply to *do...while* at all? I initially
handwaved that away, but it seems like it might also benefit... if anyone
has a use for the below pattern:
*do {*
* Stuff();*
* } while (keep_going)*
* do else {*
* IfStuffWasOnlyDoneOnce();*
* }*
* do break {*
* IfStuffWasOnlyHalfDone();*
* }*
Seems less likely, but a logical extension of the other 2, if they were to
go anywhere.
--=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/CACGiwhEq0kCp-ziM5zqdN-AGRRhnQ4D5JMue93LHH4NPVNq=
oPw%40mail.gmail.com.
--001a113d7b2eac8bf30537d83306
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
un, Jul 17, 2016 at 6:24 PM, <span dir=3D"ltr"><<a href=3D"mailto:szoll=
osi.lorand@gmail.com" target=3D"_blank">szollosi.lorand@gmail.com</a>></=
span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8e=
x;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Actual synt=
ax is not that important to me. For me, <i>for(...) { ... } for break { ...=
} for else { ... } </i>is perfectly fine, same for <i>while</i>.<span clas=
s=3D""><br><br>2016. j=C3=BAlius 17., vas=C3=A1rnap 19:02:53 UTC+2 id=C5=91=
pontban D. B. a k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote class=3D"gmail_q=
uote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;paddin=
g-left:1ex"><div dir=3D"ltr"><div>I think using <i>catch</i> here is a terr=
ible idea given its current semantics, and probably not grammatically viabl=
e anyway. Insisting on that keyword is liable to sink this proposal before =
it could ever get anywhere.<br><br></div>Why not just <i>for (...) { /* thi=
ngs if condition =3D=3D true */ } for else { /* things if condition =3D=3D =
false */ }</i><br></div>
</blockquote></span></div><span class=3D"">
</span></blockquote><div><br></div><div><br>Yeah, <i>{for/while} {break/els=
e}</i> definitely get my vote for the moment.<br><br></div><div>Btw, would =
you want this to apply to <i>do...while</i> at all? I initially handwaved t=
hat away, but it seems like it might also benefit... if anyone has a use fo=
r the below pattern:<br><br></div><div>=C2=A0=C2=A0=C2=A0 <i>do {<br></i></=
div><div><i>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Stuff();<br></i></di=
v><div><i>=C2=A0=C2=A0=C2=A0 } while (keep_going)<br></i></div><div><i>=C2=
=A0=C2=A0=C2=A0 do else {<br></i></div><div><i>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 IfStuffWasOnlyDoneOnce();<br></i></div><div><i>=C2=A0=C2=A0=
=C2=A0 }<br></i></div><div><i>=C2=A0=C2=A0=C2=A0 do break {<br></i></div><d=
iv><i>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 IfStuffWasOnlyHalfDone();<=
br></i></div><div><i>=C2=A0=C2=A0=C2=A0 }<br><br></i></div><div>Seems less =
likely, but a logical extension of the other 2, if they were to go anywhere=
..<br><br></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" 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/CACGiwhEq0kCp-ziM5zqdN-AGRRhnQ4D5JMue=
93LHH4NPVNqoPw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhEq0kCp-ziM=
5zqdN-AGRRhnQ4D5JMue93LHH4NPVNqoPw%40mail.gmail.com</a>.<br />
--001a113d7b2eac8bf30537d83306--
.
Author: "D. B." <db0451@gmail.com>
Date: Sun, 17 Jul 2016 18:30:55 +0100
Raw View
--001a114b14e0d6f60f0537d8363d
Content-Type: text/plain; charset=UTF-8
and since I apparently can't take my own advice given in the same post,
those should be *while else* and *while break*
--
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/CACGiwhGFMoRLESq%3DKP9RQaHNTurNGeJXACgEV9_e1sLoNwRK9g%40mail.gmail.com.
--001a114b14e0d6f60f0537d8363d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">and since I apparently can't take my own advice given =
in the same post, those should be <i>while else</i> and <i>while break</i><=
br></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CACGiwhGFMoRLESq%3DKP9RQaHNTurNGeJXAC=
gEV9_e1sLoNwRK9g%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhGFMoRLES=
q%3DKP9RQaHNTurNGeJXACgEV9_e1sLoNwRK9g%40mail.gmail.com</a>.<br />
--001a114b14e0d6f60f0537d8363d--
.
Author: szollosi.lorand@gmail.com
Date: Sun, 17 Jul 2016 10:32:18 -0700 (PDT)
Raw View
------=_Part_432_416393982.1468776738979
Content-Type: multipart/alternative;
boundary="----=_Part_433_726432210.1468776738979"
------=_Part_433_726432210.1468776738979
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Thanks! This is very promising, however, I miss the `catch empty` branch.=
=20
With that, our syntax would look like: *{*for*|*while*}*(...) { ... } catch=
=20
default ... catch break ... catch() ...
I leave it up for your votes whether we should use:
- catch
- else, *{*for*|*while*}* else
- case
- when (or any new keyword)
=20
2016. j=C3=BAlius 17., vas=C3=A1rnap 19:03:13 UTC+2 id=C5=91pontban Ville V=
outilainen a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> On 17 July 2016 at 17:38, lorro (lo...@lorro.hu <javascript:>)=20
> <szollos...@gmail.com <javascript:>> wrote:=20
> > Many cases, specific handling is required when the body of the for loop=
=20
> was=20
> > not executed. These include variable initializations which would've=20
> gotten=20
>
> See http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0082r1.pdf=20
>
> That paper didn't gain consensus in Jacksonville. Different approaches=20
> might come up for C++20.=20
>
--=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/a104b183-1751-4144-a3eb-5ee6232c03e5%40isocpp.or=
g.
------=_Part_433_726432210.1468776738979
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Thanks! This is very promising, however, I miss the `catch=
empty` branch. With that, our syntax would look like: <b>{</b>for<b>|</b>w=
hile<b>}</b>(...) { ... } catch default ... catch break ... catch() ...<br>=
<br>I leave it up for your votes whether we should use:<br><ul><li>catch</l=
i><li>else, <b>{</b>for<b>|</b>while<b>}</b> else<br></li><li>case<br></li>=
<li>when (or any new keyword)<br></li></ul><br>2016. j=C3=BAlius 17., vas=
=C3=A1rnap 19:03:13 UTC+2 id=C5=91pontban Ville Voutilainen a k=C3=B6vetkez=
=C5=91t =C3=ADrta:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 17 July 2=
016 at 17:38, lorro (<a href=3D"javascript:" target=3D"_blank" gdf-obfuscat=
ed-mailto=3D"nD6VdwI9DAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'=
;javascript:';return true;" onclick=3D"this.href=3D'javascript:'=
;;return true;">lo...@lorro.hu</a>)
<br><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
nD6VdwI9DAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">szollos...@gmail.com</a>> wrote:
<br>> Many cases, specific handling is required when the body of the for=
loop was
<br>> not executed. These include variable initializations which would&#=
39;ve gotten
<br>
<br>See <a href=3D"http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p008=
2r1.pdf" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'=
;http://www.google.com/url?q\x3dhttp%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FW=
G21%2Fdocs%2Fpapers%2F2016%2Fp0082r1.pdf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3d=
AFQjCNFmPuBvYDKTR4N5O4MdQNkVWvetTA';return true;" onclick=3D"this.href=
=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fopen-std.org%2FJTC1%2FS=
C22%2FWG21%2Fdocs%2Fpapers%2F2016%2Fp0082r1.pdf\x26sa\x3dD\x26sntz\x3d1\x26=
usg\x3dAFQjCNFmPuBvYDKTR4N5O4MdQNkVWvetTA';return true;">http://open-st=
d.org/JTC1/SC22/<wbr>WG21/docs/papers/2016/p0082r1.<wbr>pdf</a>
<br>
<br>That paper didn't gain consensus in Jacksonville. Different approac=
hes
<br>might come up for C++20.
<br></blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a104b183-1751-4144-a3eb-5ee6232c03e5%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a104b183-1751-4144-a3eb-5ee6232c03e5=
%40isocpp.org</a>.<br />
------=_Part_433_726432210.1468776738979--
------=_Part_432_416393982.1468776738979--
.
Author: "D. B." <db0451@gmail.com>
Date: Sun, 17 Jul 2016 18:43:44 +0100
Raw View
--94eb2c0d7c60b112d90537d8644b
Content-Type: text/plain; charset=UTF-8
On Sun, Jul 17, 2016 at 6:32 PM, <szollosi.lorand@gmail.com> wrote:
> Thanks! This is very promising, however, I miss the `catch empty` branch.
> With that, our syntax would look like: *{*for*|*while*}*(...) { ... }
> catch default ... catch break ... catch() ...
>
> I leave it up for your votes whether we should use:
>
> - catch
> - else, *{*for*|*while*}* else
> - case
> - when (or any new keyword)
>
> Labels of* false *(condition failed), *break*, and *default* (all
iterations ran fully) are actually mildly appealing.
*case* as the label-defining keyword seemed nice too, but I such labels
would be wholly ambiguous if said loops are contained within a *switch*
block. This probably makes *case* infeasible.
*for/while *as the keyword seems nice and isn't really confusing. but hey -
*register* is "unused and reserved" as of C++17, and works well as a verb
;-)
--
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/CACGiwhGT-xztXPSejE_y4KFDomD6tYJ7gOfzK1tKEC-8oWebLg%40mail.gmail.com.
--94eb2c0d7c60b112d90537d8644b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
un, Jul 17, 2016 at 6:32 PM, <span dir=3D"ltr"><<a href=3D"mailto:szoll=
osi.lorand@gmail.com" target=3D"_blank">szollosi.lorand@gmail.com</a>></=
span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8e=
x;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Thanks! Thi=
s is very promising, however, I miss the `catch empty` branch. With that, o=
ur syntax would look like: <b>{</b>for<b>|</b>while<b>}</b>(...) { ... } ca=
tch default ... catch break ... catch() ...<br><br>I leave it up for your v=
otes whether we should use:<br><ul><li>catch</li><li>else, <b>{</b>for<b>|<=
/b>while<b>}</b> else<br></li><li>case<br></li><li>when (or any new keyword=
)<br></li></ul></div></blockquote><div>Labels of<i> false </i>(condition fa=
iled), <i>break</i>, and <i>default</i> (all iterations ran fully) are actu=
ally mildly appealing.<br><br><i>case</i> as the label-defining keyword see=
med nice too, but I such labels would be wholly ambiguous if said loops are=
contained within a <i>switch</i> block. This probably makes <i>case</i> in=
feasible. <br></div><div>=C2=A0<br></div><div><i>for/while </i>as the keywo=
rd seems nice and isn't really confusing. but hey - <b>register</b> is =
"unused and reserved" as of C++17, and works well as a verb ;-)<b=
r><br></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" 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/CACGiwhGT-xztXPSejE_y4KFDomD6tYJ7gOfz=
K1tKEC-8oWebLg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhGT-xztXPSe=
jE_y4KFDomD6tYJ7gOfzK1tKEC-8oWebLg%40mail.gmail.com</a>.<br />
--94eb2c0d7c60b112d90537d8644b--
.
Author: szollosi.lorand@gmail.com
Date: Sun, 17 Jul 2016 10:47:13 -0700 (PDT)
Raw View
------=_Part_3295_211748944.1468777633824
Content-Type: multipart/alternative;
boundary="----=_Part_3296_425322644.1468777633831"
------=_Part_3296_425322644.1468777633831
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=20
- Another proposal (that I also would like to see) is to have range=20
schema for *std::optional<>*. In that case, you could do: *for( auto&=20
val : getVal() ) { return handle(val); } for else { return error(); }*.=
=20
Notice that the optional didn't explicitly appear anywhere, so it might=
=20
very well get optimized away.
- Any loop that tries to find an element - and then do something to it=
=20
before returning - could be easier written using *for break*
- In case when the loop condition is expensive or alters state (thus=20
cannot be repeated). we currently need to introduce a new bool variable.=
=20
Two if you want early exit. These are both unneeded cost (additional *if=
*=20
executed) and maintenance issues (as it's easy to miss the bool).
- Some search-like and accumulate-like loops might be way easier written=
=20
this way.
- Zero elements in a container is sometimes different and requires=20
special handling. E.g. when the constructor sees that there are zero=20
elements, it might as well not allocate anything and just assign nullptr=
to=20
a buffer. I understand that this is just a minor optimization.
=20
2016. j=C3=BAlius 17., vas=C3=A1rnap 19:24:24 UTC+2 id=C5=91pontban D. B. a=
k=C3=B6vetkez=C5=91t=20
=C3=ADrta:
>
> On Sun, Jul 17, 2016 at 6:19 PM, Tony V E <tvan...@gmail.com <javascript:=
>
> > wrote:
>
>> I have my doubts about whether the proposal is useful enough to spend=20
>> time on,
>> But I like 'for else' better than catch.=20
>>
>> But even better would be 'or else'=E2=80=8E :-)
>>
>
> I dunno, it does touch on break-out cases whose verbosity has annoyed me=
=20
> in the past - while being nowhere near the complexity of some examples in=
=20
> that paper - and it looks very logical, chosen labels notwithstanding.
>
> "or else" is funny, but I think for ultimate clarity, it should be "xor=
=20
> else" ;-)=20
>
>
>
--=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/0c1b5fe5-8f0e-4b29-a0c7-f0bfc5c2eb97%40isocpp.or=
g.
------=_Part_3296_425322644.1468777633831
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><ul><li>Another proposal (that I also would like to see) i=
s to have range schema for <i>std::optional<></i>. In that case, you =
could do: <i>for( auto& val : getVal() ) { return handle(val); } for el=
se { return error(); }</i>. Notice that the optional didn't explicitly =
appear anywhere, so it might very well get optimized away.</li><li>Any loop=
that tries to find an element - and then do something to it before returni=
ng - could be easier written using <i>for break</i></li><li>In case when th=
e loop condition is expensive or alters state (thus cannot be repeated). we=
currently need to introduce a new bool variable. Two if you want early exi=
t. These are both unneeded cost (additional <i>if</i> executed) and mainten=
ance issues (as it's easy to miss the bool).</li><li>Some search-like a=
nd accumulate-like loops might be way easier written this way.</li><li>Zero=
elements in a container is sometimes different and requires special handli=
ng. E.g. when the constructor sees that there are zero elements, it might a=
s well not allocate anything and just assign nullptr to a buffer. I underst=
and that this is just a minor optimization.<br></li></ul><br>2016. j=C3=BAl=
ius 17., vas=C3=A1rnap 19:24:24 UTC+2 id=C5=91pontban D. B. a k=C3=B6vetkez=
=C5=91t =C3=ADrta:<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><div class=3D"gmail_quote">On Sun, Jul 17, 2016 at 6:19 PM, Tony =
V E <span dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank" gdf-obf=
uscated-mailto=3D"WX9NYSo-DAAJ" rel=3D"nofollow" onmousedown=3D"this.href=
=3D'javascript:';return true;" onclick=3D"this.href=3D'javascri=
pt:';return true;">tvan...@gmail.com</a>></span> wrote:<br><blockquo=
te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px =
solid rgb(204,204,204);padding-left:1ex"><div style=3D"background-color:rgb=
(255,255,255);line-height:initial" lang=3D"en-US"> =
<div style=3D"=
width:100%;font-size:initial;font-family:Calibri,"Slate Pro",sans=
-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:=
rgb(255,255,255)">I have my doubts about whether the proposal is useful eno=
ugh to spend time on,</div><div style=3D"width:100%;font-size:initial;font-=
family:Calibri,"Slate Pro",sans-serif,sans-serif;color:rgb(31,73,=
125);text-align:initial;background-color:rgb(255,255,255)">But I like '=
for else' better than catch.=C2=A0</div><div style=3D"width:100%;font-s=
ize:initial;font-family:Calibri,"Slate Pro",sans-serif,sans-serif=
;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"=
><br></div><div style=3D"width:100%;font-size:initial;font-family:Calibri,&=
quot;Slate Pro",sans-serif,sans-serif;color:rgb(31,73,125);text-align:=
initial;background-color:rgb(255,255,255)">But even better would be 'or=
else'=E2=80=8E :-)</div></div></blockquote><div><br>I dunno, it does t=
ouch on break-out cases whose verbosity has annoyed me in the past - while =
being nowhere near the complexity of some examples in that paper - and=20
it looks very logical, chosen labels notwithstanding.<br><br>"or else&=
quot; is=20
funny, but I think for ultimate clarity, it should be "xor else" =
;-) <br></div></div><br><br></div></div>
</blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/0c1b5fe5-8f0e-4b29-a0c7-f0bfc5c2eb97%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0c1b5fe5-8f0e-4b29-a0c7-f0bfc5c2eb97=
%40isocpp.org</a>.<br />
------=_Part_3296_425322644.1468777633831--
------=_Part_3295_211748944.1468777633824--
.
Author: szollosi.lorand@gmail.com
Date: Sun, 17 Jul 2016 10:58:36 -0700 (PDT)
Raw View
------=_Part_1805_1552191590.1468778316828
Content-Type: multipart/alternative;
boundary="----=_Part_1806_346272959.1468778316829"
------=_Part_1806_346272959.1468778316829
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Sounds logical to include them as well...
2016. j=C3=BAlius 17., vas=C3=A1rnap 19:30:05 UTC+2 id=C5=91pontban D. B. a=
k=C3=B6vetkez=C5=91t=20
=C3=ADrta:
>
> On Sun, Jul 17, 2016 at 6:24 PM, <szollos...@gmail.com <javascript:>>=20
> wrote:
>
>> Actual syntax is not that important to me. For me, *for(...) { ... } for=
=20
>> break { ... } for else { ... } *is perfectly fine, same for *while*.
>>
>> 2016. j=C3=BAlius 17., vas=C3=A1rnap 19:02:53 UTC+2 id=C5=91pontban D. B=
.. a k=C3=B6vetkez=C5=91t=20
>> =C3=ADrta:
>>>
>>> I think using *catch* here is a terrible idea given its current=20
>>> semantics, and probably not grammatically viable anyway. Insisting on t=
hat=20
>>> keyword is liable to sink this proposal before it could ever get anywhe=
re.
>>>
>>> Why not just *for (...) { /* things if condition =3D=3D true */ } for e=
lse=20
>>> { /* things if condition =3D=3D false */ }*
>>>
>>
>
> Yeah, *{for/while} {break/else}* definitely get my vote for the moment.
>
> Btw, would you want this to apply to *do...while* at all? I initially=20
> handwaved that away, but it seems like it might also benefit... if anyone=
=20
> has a use for the below pattern:
>
> =20
> *do {*
>
> * Stuff();*
>
> * } while (keep_going)*
>
> * do else {*
>
> * IfStuffWasOnlyDoneOnce();*
>
> * }*
>
> * do break {*
>
> * IfStuffWasOnlyHalfDone();*
>
>
> * }*
> Seems less likely, but a logical extension of the other 2, if they were t=
o=20
> go anywhere.
>
>
--=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/ef73576a-186a-4985-8719-8c03a0fec9ed%40isocpp.or=
g.
------=_Part_1806_346272959.1468778316829
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Sounds logical to include them as well...<br><br>2016. j=
=C3=BAlius 17., vas=C3=A1rnap 19:30:05 UTC+2 id=C5=91pontban D. B. a k=C3=
=B6vetkez=C5=91t =C3=ADrta:<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"><div><div class=3D"gmail_quote">On Sun, Jul 17, 2016 at 6:24 =
PM, <span dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank" gdf-ob=
fuscated-mailto=3D"vuTUmXk-DAAJ" rel=3D"nofollow" onmousedown=3D"this.href=
=3D'javascript:';return true;" onclick=3D"this.href=3D'javascri=
pt:';return true;">szollos...@gmail.com</a>></span> wrote:<br><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
solid;padding-left:1ex"><div dir=3D"ltr">Actual syntax is not that importa=
nt to me. For me, <i>for(...) { ... } for break { ... } for else { ... } </=
i>is perfectly fine, same for <i>while</i>.<span><br><br>2016. j=C3=BAlius =
17., vas=C3=A1rnap 19:02:53 UTC+2 id=C5=91pontban D. B. a k=C3=B6vetkez=C5=
=91t =C3=ADrta:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-l=
eft:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><di=
v>I think using <i>catch</i> here is a terrible idea given its current sema=
ntics, and probably not grammatically viable anyway. Insisting on that keyw=
ord is liable to sink this proposal before it could ever get anywhere.<br><=
br></div>Why not just <i>for (...) { /* things if condition =3D=3D true */ =
} for else { /* things if condition =3D=3D false */ }</i><br></div>
</blockquote></span></div><span>
</span></blockquote><div><br></div><div><br>Yeah, <i>{for/while} {break/els=
e}</i> definitely get my vote for the moment.<br><br></div><div>Btw, would =
you want this to apply to <i>do...while</i> at all? I initially handwaved t=
hat away, but it seems like it might also benefit... if anyone has a use fo=
r the below pattern:<br><br></div><div>=C2=A0=C2=A0=C2=A0 <i>do {<br></i></=
div><div><i>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Stuff();<br></i></di=
v><div><i>=C2=A0=C2=A0=C2=A0 } while (keep_going)<br></i></div><div><i>=C2=
=A0=C2=A0=C2=A0 do else {<br></i></div><div><i>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 IfStuffWasOnlyDoneOnce();<br></i></div><div><i>=C2=A0=C2=A0=
=C2=A0 }<br></i></div><div><i>=C2=A0=C2=A0=C2=A0 do break {<br></i></div><d=
iv><i>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 IfStuffWasOnlyHalfDone();<=
br></i></div><div><i>=C2=A0=C2=A0=C2=A0 }<br><br></i></div><div>Seems less =
likely, but a logical extension of the other 2, if they were to go anywhere=
..<br><br></div></div></div></div>
</blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ef73576a-186a-4985-8719-8c03a0fec9ed%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ef73576a-186a-4985-8719-8c03a0fec9ed=
%40isocpp.org</a>.<br />
------=_Part_1806_346272959.1468778316829--
------=_Part_1805_1552191590.1468778316828--
.
Author: Derek Ross <antiquarktv@gmail.com>
Date: Sun, 17 Jul 2016 12:00:36 -0700 (PDT)
Raw View
------=_Part_1198_138247497.1468782036964
Content-Type: multipart/alternative;
boundary="----=_Part_1199_857677263.1468782036964"
------=_Part_1199_857677263.1468782036964
Content-Type: text/plain; charset=UTF-8
Once the "if initializers" appear in C++17, you could almost get what you
want through a macro:
#define if_for(init,cond,incr) if(init ; cond)for(;cond;incr)
....
if_for(int i = 0 ; i < n ; i ++)
{
...etc...
}else{
cout << "cond was false\n";
}
Hmmm... maybe you could use "if for" as the syntax, which AFAIK is
currently illegal in C/C++.
----
Cheers,
Derek
On Sunday, July 17, 2016 at 9:38:12 AM UTC-5, lorro (lorro@***) wrote:
>
> Many cases, specific handling is required when the body of the for loop
> was not executed. These include variable initializations which would've
> gotten value inside the loop, or throwing exceptions. Currently, these
> either need double-checking, which is inefficient, or copying the
> condition, which is error-prone, like:
>
> {
> *init;*
> if(*cond*)
> do
> {
> *body*
> incr;
> } while(*cond*)
> else
> *body-not-executed*
> }
>
> Note that this is still not exactly what we wanted as variables declared
> in init are still visible in else branch. Any alternative requires
> double-checking or introducing a boolean variable that's updated in init
> and incr. What I'd recommend instead is allowing an else after for:
>
> for(*init*;* cond*; *incr*)
> *body*
> else
>
>
>
>
> *body-not-executedor,*for(* init *:* range *)
>
> * body*else
> *body-not-executed*
>
> As expected, body-not-executed should run iff cond has failed for the
> first time (or range was empty); in other words, if body was not executed.
> Optimizing compilers can unroll this easily and generate optimal code.
> Also, it does not clash with other language features as else is currently
> only allowed after an if.
> What do you think?
>
--
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/4ae43aae-50dc-42d9-adba-207ff6dc0c4d%40isocpp.org.
------=_Part_1199_857677263.1468782036964
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Once the "if initializers" appear in C++17, you =
could almost get what you want through a macro:<br><br><div class=3D"pretty=
print" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187=
, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-word;=
"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
#800;" class=3D"styled-by-prettify">#define</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> if_for</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">init</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">cond</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify">incr</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">init </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> cond</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">)</span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">for</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">cond</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">incr</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">...</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 if_for</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> i </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #066;" class=3D"styled-by-prettify">0</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"> i </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> n </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> i </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>++)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">...=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">etc</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">...</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">else</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 cout </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;"=
class=3D"styled-by-prettify">"cond was false\n"</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br><br></span></div></code></div><br>Hmmm..=
.. maybe you could use "if for" as the syntax, which AFAIK is curr=
ently illegal in C/C++. <br><br>----<br>Cheers, <br>Derek<br><br>On Sunday,=
July 17, 2016 at 9:38:12 AM UTC-5, lorro (lorro@***) wrote:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Many cases, specific handlin=
g is required when the body of the for loop was not executed. These include=
variable initializations which would've gotten value inside the loop, =
or throwing exceptions. Currently, these either need double-checking, which=
is inefficient, or copying the condition, which is error-prone, like:<br><=
span style=3D"font-family:courier new,monospace"><br>{<br>=C2=A0=C2=A0=C2=
=A0 <i>init;</i><br>=C2=A0=C2=A0=C2=A0 if(<i>cond</i>)<br>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 do<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 {<br>=C2=
=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body</i><br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 incr;<br>=C2=A0 =
=C2=A0=C2=A0 =C2=A0=C2=A0 } while(<i>cond</i>)<br>=C2=A0=C2=A0=C2=A0 else<b=
r>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body-not-executed</i><br>}<br><br><sp=
an style=3D"font-family:arial,sans-serif">Note that this is still not exact=
ly what we wanted as variables declared in init are still visible in else b=
ranch. Any alternative requires double-checking or introducing a boolean va=
riable that's updated in init and incr. What I'd recommend instead =
is allowing an else after for:<br><br><font face=3D"courier new,monospace">=
for(<i>init</i>;<i> cond</i>; <i>incr</i>)<br>=C2=A0=C2=A0=C2=A0 <i>body</i=
><br>else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-executed<br><br><font face=3D"a=
rial,sans-serif">or,<br><br></font></i><font face=3D"arial,sans-serif"><fon=
t face=3D"courier new,monospace">for(</font></font><i><font face=3D"arial,s=
ans-serif"><font face=3D"courier new,monospace"> init </font></font></i><fo=
nt face=3D"arial,sans-serif"><font face=3D"courier new,monospace">:</font><=
/font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospac=
e"> range </font></font></i><font face=3D"arial,sans-serif"><font face=3D"c=
ourier new,monospace">)</font></font><i><font face=3D"arial,sans-serif"><fo=
nt face=3D"courier new,monospace"><br>=C2=A0=C2=A0=C2=A0 body<br></font></f=
ont></i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospace=
">else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-executed</i><br></font></font><i><=
font face=3D"arial,sans-serif"><font face=3D"courier new,monospace"></font>=
</font><br></i><span style=3D"font-family:arial,sans-serif">As expected, bo=
dy-not-executed should run iff cond has failed for the first time (or range=
was empty); in other words, if body was not executed. Optimizing compilers=
can unroll this easily and generate optimal code. Also, it does not clash =
with other language features as else is currently only allowed after an if.=
<br>What do you think?<br><font face=3D"courier new,monospace"></font></sp=
an></font></span></span></div></blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4ae43aae-50dc-42d9-adba-207ff6dc0c4d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4ae43aae-50dc-42d9-adba-207ff6dc0c4d=
%40isocpp.org</a>.<br />
------=_Part_1199_857677263.1468782036964--
------=_Part_1198_138247497.1468782036964--
.
Author: szollosi.lorand@gmail.com
Date: Mon, 18 Jul 2016 00:30:34 -0700 (PDT)
Raw View
------=_Part_8_1663610364.1468827034636
Content-Type: multipart/alternative;
boundary="----=_Part_9_1622107131.1468827034637"
------=_Part_9_1622107131.1468827034637
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This evaluates cond twice. Albeit, with double do-while, that's feasible:
if(*init* ; *cond*) do { do *body* while(false); *incr*; } while(*cond*);
still not the most beautiful syntax...
---
Another thing, while we are here, that I miss is 'first-round initializer':=
=20
that is, an initializer that's run *after* cond is checked. There are=20
situations when the value you wish to initialize a variable to depends on=
=20
the first value produced by the loop and no default constructor is=20
available (or can be expected if it's a template type). If, furthermore,=20
your range is such that you cannot 'go back' (i.e., iterator::operator++()=
=20
invalidates and deallocates the original iterator and it's value), and/or=
=20
checking loop condition is very expensive, you might suddenly find yourself=
=20
using *std::optional<>* (or pointer to a heap-allocated object) and=20
checking in each iteration.
Consider this max algorithm instead:
template<typename Range>
auto max(const Range& range) // possibly Range&& as well
{
for( auto v : range; auto m =3D v )
if( m < v ) m=3Dv;
for default // use whichever syntax you prefer
return std::make_optional( m );
for else
return std::nullopt;
}
This also shows the requirement that any variables declared in *for* should=
=20
be available in *for else* and *for default*.
A completely generic syntax could have the following elements (let me know=
=20
if any further), out of which we might choose which ones to support:
- (precondition: this is handled by an initial *if* very well, probably no=
=20
additional support needed)
- (pre-fail: this is handled by an initial *if-else*, probably no=20
additional support needed)
- either:
*- *init: this is the first parameter of the *for(;;)* syntax
*- *head-cond: this is the second parameter of the *for(;;)* syntax
*- *incr: this is the third parameter of the *for(;;)* syntax
- postinit: this could be the 4th parameter of the above syntax, like=
=20
*for(;;;)* or
- range-init: this is the current *for( : )* syntax
- postinit: this could be the second parameter of the above syntax,=20
like=20
*for(;;;)-* body, which we have now
- continue statement(s) in body, which execute incr, then body iff=20
tail-cond && head-cond.
- break statement(s) in body, which go to tail-break
- tail-cond: this is what we have with *do { } while( )*, in a generic (in=
=20
theory, not necessarily in practice*) *framework these can be united
- tails: zero or more distinct element of:
- tail-break: executed when the loop finished due to *break*
* - *tail-default: executed when we successfully entered at least once=
=20
to the body of the loop (i.e., head-cond was true at least once) and there=
=20
were no exceptions
- tail-else: executed when head-cond was false for the first time
- (tail-catch: this is handled very well by try-catch, probably no=20
additional support needed)
What do you think and how would you name each of these elements? Did I miss=
=20
something, is there a better definition to come up with, should any points=
=20
be refined?
Thanks,
-lorro
2016. j=C3=BAlius 17., vas=C3=A1rnap 21:00:37 UTC+2 id=C5=91pontban Derek R=
oss a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> Once the "if initializers" appear in C++17, you could almost get what you=
=20
> want through a macro:
>
>
> #define if_for(init,cond,incr) if(init ; cond)for(;cond;incr)
> ...
> if_for(int i =3D 0 ; i < n ; i ++)
> {
> ...etc...
> }else{
> cout << "cond was false\n";
> }
>
>
> Hmmm... maybe you could use "if for" as the syntax, which AFAIK is=20
> currently illegal in C/C++.=20
>
> ----
> Cheers,=20
> Derek
>
> On Sunday, July 17, 2016 at 9:38:12 AM UTC-5, lorro (lorro@***) wrote:
>>
>> Many cases, specific handling is required when the body of the for loop=
=20
>> was not executed. These include variable initializations which would've=
=20
>> gotten value inside the loop, or throwing exceptions. Currently, these=
=20
>> either need double-checking, which is inefficient, or copying the=20
>> condition, which is error-prone, like:
>>
>> {
>> *init;*
>> if(*cond*)
>> do
>> {
>> *body*
>> incr;
>> } while(*cond*)
>> else
>> *body-not-executed*
>> }
>>
>> Note that this is still not exactly what we wanted as variables declared=
=20
>> in init are still visible in else branch. Any alternative requires=20
>> double-checking or introducing a boolean variable that's updated in init=
=20
>> and incr. What I'd recommend instead is allowing an else after for:
>>
>> for(*init*;* cond*; *incr*)
>> *body*
>> else
>> =20
>>
>>
>>
>> *body-not-executedor,*for(* init *:* range *)
>>
>> * body*else
>> *body-not-executed*
>>
>> As expected, body-not-executed should run iff cond has failed for the=20
>> first time (or range was empty); in other words, if body was not execute=
d.=20
>> Optimizing compilers can unroll this easily and generate optimal code.=
=20
>> Also, it does not clash with other language features as else is currentl=
y=20
>> only allowed after an if.=20
>> What do you think?
>>
>
--=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/0a7a3dec-2f4b-42e1-890c-0c42f20c08a1%40isocpp.or=
g.
------=_Part_9_1622107131.1468827034637
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">This evaluates cond twice. Albeit, with double do-while, t=
hat's feasible:<br><br>if(<i>init</i> ; <i>cond</i>) do { do <i>body</i=
> while(false); <i>incr</i>; } while(<i>cond</i>);<br><br>still not the mos=
t beautiful syntax...<br><br><br>---<br><br>Another thing, while we are her=
e, that I miss is 'first-round initializer': that is, an initialize=
r that's run <i>after</i> cond is checked. There are situations when th=
e value you wish to initialize a variable to depends on the first value pro=
duced by the loop and no default constructor is available (or can be expect=
ed if it's a template type). If, furthermore, your range is such that y=
ou cannot 'go back' (i.e., iterator::operator++() invalidates and d=
eallocates the original iterator and it's value), and/or checking loop =
condition is very expensive, you might suddenly find yourself using <i>std:=
:optional<></i> (or pointer to a heap-allocated object) and checking =
in each iteration.<br>Consider this max algorithm instead:<br><br>template&=
lt;typename Range><br>auto max(const Range& range) // possibly Range=
&& as well<br>{<br>=C2=A0=C2=A0=C2=A0 for( auto v : range; auto m =
=3D v )<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if( m < v ) m=3Dv;=
<br>=C2=A0=C2=A0=C2=A0 for default=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // use whichever syntax you p=
refer<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return std::make_option=
al( m );<br>=C2=A0=C2=A0=C2=A0 for else<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 return std::nullopt;<br>}<br><br>This also shows the requireme=
nt that any variables declared in <i>for</i> should be available in <i>for =
else</i> and <i>for default</i>.<br><br>A completely generic syntax could h=
ave the following elements (let me know if any further), out of which we mi=
ght choose which ones to support:<br><br>- (precondition: this is handled b=
y an initial <i>if</i> very well, probably no additional support needed)<br=
>- (pre-fail: this is handled by an initial <i>if-else</i>, probably no add=
itional support needed)<br>- either:<br>=C2=A0=C2=A0=C2=A0 <i>- </i>init: t=
his is the first parameter of the <i>for(;;)</i> syntax<br>=C2=A0=C2=A0=C2=
=A0 <i>- </i>head-cond: this is the second parameter of the <i>for(;;)</i> =
syntax<br>=C2=A0=C2=A0=C2=A0 <i>- </i>incr: this is the third parameter of =
the <i>for(;;)</i> syntax<br>=C2=A0=C2=A0=C2=A0 - postinit: this could be t=
he 4th parameter of the above syntax, like <i>for(;;;)<br></i>=C2=A0 or<br>=
=C2=A0=C2=A0=C2=A0 - range-init: this is the current <i>for( : )</i> syntax=
<br>=C2=A0=C2=A0=C2=A0 - postinit: this could be the second parameter of th=
e above syntax, like <i>for(;;;)<br>-</i> body, which we have now<br>=C2=A0=
=C2=A0=C2=A0 - continue statement(s) in body, which execute incr, then body=
iff tail-cond && head-cond.<br>=C2=A0=C2=A0=C2=A0 - break statemen=
t(s) in body, which go to tail-break<br>- tail-cond: this is what we have w=
ith <i>do { } while( )</i>, in a generic (in theory, not necessarily in pra=
ctice<i>) </i>framework these can be united<br>- tails: zero or more distin=
ct element of:<br>=C2=A0=C2=A0=C2=A0 - tail-break: executed when the loop f=
inished due to <i>break</i><br><i>=C2=A0=C2=A0=C2=A0 - </i>tail-default: ex=
ecuted when we successfully entered at least once to the body of the loop (=
i.e., head-cond was true at least once) and there were no exceptions<br>=C2=
=A0=C2=A0=C2=A0 - tail-else: executed when head-cond was false for the firs=
t time<br>=C2=A0=C2=A0=C2=A0 - (tail-catch: this is handled very well by tr=
y-catch, probably no additional support needed)<br><br>What do you think an=
d how would you name each of these elements? Did I miss something, is there=
a better definition to come up with, should any points be refined?<br><br>=
Thanks,<br>-lorro<br><i><br></i>2016. j=C3=BAlius 17., vas=C3=A1rnap 21:00:=
37 UTC+2 id=C5=91pontban Derek Ross a k=C3=B6vetkez=C5=91t =C3=ADrta:<block=
quote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-le=
ft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Once the "if i=
nitializers" appear in C++17, you could almost get what you want throu=
gh a macro:<br><br><div style=3D"background-color:rgb(250,250,250);border-c=
olor:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-w=
ord"><code><div><span style=3D"color:#000"><br></span><span style=3D"color:=
#800">#define</span><span style=3D"color:#000"> if_for</span><span style=3D=
"color:#660">(</span><span style=3D"color:#000">init</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000">cond</span><span style=3D"col=
or:#660">,</span><span style=3D"color:#000">incr</span><span style=3D"color=
:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#008=
">if</span><span style=3D"color:#660">(</span><span style=3D"color:#000">in=
it </span><span style=3D"color:#660">;</span><span style=3D"color:#000"> co=
nd</span><span style=3D"color:#660">)</span><span style=3D"color:#008">for<=
/span><span style=3D"color:#660">(;</span><span style=3D"color:#000">cond</=
span><span style=3D"color:#660">;</span><span style=3D"color:#000">incr</sp=
an><span style=3D"color:#660">)</span><span style=3D"color:#000"><br></span=
><span style=3D"color:#660">...</span><span style=3D"color:#000"><br>=C2=A0=
if_for</span><span style=3D"color:#660">(</span><span style=3D"color:#008"=
>int</span><span style=3D"color:#000"> i </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:#000"> </span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"> i </span><span style=3D"color:#660"><</span>=
<span style=3D"color:#000"> n </span><span style=3D"color:#660">;</span><sp=
an style=3D"color:#000"> i </span><span style=3D"color:#660">++)</span><spa=
n style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#660">{</span=
><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#=
660">...</span><span style=3D"color:#000">etc</span><span style=3D"color:#6=
60">...</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"c=
olor:#660">}</span><span style=3D"color:#008">else</span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 cout </span><=
span style=3D"color:#660"><<</span><span style=3D"color:#000"> </span=
><span style=3D"color:#080">"cond was false\n"</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 </span><span =
style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span></di=
v></code></div><br>Hmmm... maybe you could use "if for" as the sy=
ntax, which AFAIK is currently illegal in C/C++. <br><br>----<br>Cheers, <b=
r>Derek<br><br>On Sunday, July 17, 2016 at 9:38:12 AM UTC-5, lorro (lorro@*=
**) 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">Many cas=
es, specific handling is required when the body of the for loop was not exe=
cuted. These include variable initializations which would've gotten val=
ue inside the loop, or throwing exceptions. Currently, these either need do=
uble-checking, which is inefficient, or copying the condition, which is err=
or-prone, like:<br><span style=3D"font-family:courier new,monospace"><br>{<=
br>=C2=A0=C2=A0=C2=A0 <i>init;</i><br>=C2=A0=C2=A0=C2=A0 if(<i>cond</i>)<br=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 do<br>=C2=A0 =C2=A0=C2=A0 =C2=
=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body<=
/i><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 i=
ncr;<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 } while(<i>cond</i>)<br>=C2=A0=C2=
=A0=C2=A0 else<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body-not-executed</i>=
<br>}<br><br><span style=3D"font-family:arial,sans-serif">Note that this is=
still not exactly what we wanted as variables declared in init are still v=
isible in else branch. Any alternative requires double-checking or introduc=
ing a boolean variable that's updated in init and incr. What I'd re=
commend instead is allowing an else after for:<br><br><font face=3D"courier=
new,monospace">for(<i>init</i>;<i> cond</i>; <i>incr</i>)<br>=C2=A0=C2=A0=
=C2=A0 <i>body</i><br>else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-executed<br><b=
r><font face=3D"arial,sans-serif">or,<br><br></font></i><font face=3D"arial=
,sans-serif"><font face=3D"courier new,monospace">for(</font></font><i><fon=
t face=3D"arial,sans-serif"><font face=3D"courier new,monospace"> init </fo=
nt></font></i><font face=3D"arial,sans-serif"><font face=3D"courier new,mon=
ospace">:</font></font><i><font face=3D"arial,sans-serif"><font face=3D"cou=
rier new,monospace"> range </font></font></i><font face=3D"arial,sans-serif=
"><font face=3D"courier new,monospace">)</font></font><i><font face=3D"aria=
l,sans-serif"><font face=3D"courier new,monospace"><br>=C2=A0=C2=A0=C2=A0 b=
ody<br></font></font></i><font face=3D"arial,sans-serif"><font face=3D"cour=
ier new,monospace">else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-executed</i><br><=
/font></font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,m=
onospace"></font></font><br></i><span style=3D"font-family:arial,sans-serif=
">As expected, body-not-executed should run iff cond has failed for the fir=
st time (or range was empty); in other words, if body was not executed. Opt=
imizing compilers can unroll this easily and generate optimal code. Also, i=
t does not clash with other language features as else is currently only all=
owed after an if. <br>What do you think?<br><font face=3D"courier new,monos=
pace"></font></span></font></span></span></div></blockquote></div></blockqu=
ote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/0a7a3dec-2f4b-42e1-890c-0c42f20c08a1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0a7a3dec-2f4b-42e1-890c-0c42f20c08a1=
%40isocpp.org</a>.<br />
------=_Part_9_1622107131.1468827034637--
------=_Part_8_1663610364.1468827034636--
.
Author: szollosi.lorand@gmail.com
Date: Mon, 18 Jul 2016 00:48:00 -0700 (PDT)
Raw View
------=_Part_50_1888005697.1468828080905
Content-Type: multipart/alternative;
boundary="----=_Part_51_1192582986.1468828080905"
------=_Part_51_1192582986.1468828080905
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
'This also shows the requirement that any variables declared in *for*=20
should be available in *for else* and *for default*.'
Let me rephrase this, it holds for default and break, but certainly not for=
=20
else*.*
2016. j=C3=BAlius 18., h=C3=A9tf=C5=91 9:30:35 UTC+2 id=C5=91pontban szollo=
s...@gmail.com a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> This evaluates cond twice. Albeit, with double do-while, that's feasible:
>
> if(*init* ; *cond*) do { do *body* while(false); *incr*; } while(*cond*);
>
> still not the most beautiful syntax...
>
>
> ---
>
> Another thing, while we are here, that I miss is 'first-round=20
> initializer': that is, an initializer that's run *after* cond is checked.=
=20
> There are situations when the value you wish to initialize a variable to=
=20
> depends on the first value produced by the loop and no default constructo=
r=20
> is available (or can be expected if it's a template type). If, furthermor=
e,=20
> your range is such that you cannot 'go back' (i.e., iterator::operator++(=
)=20
> invalidates and deallocates the original iterator and it's value), and/or=
=20
> checking loop condition is very expensive, you might suddenly find yourse=
lf=20
> using *std::optional<>* (or pointer to a heap-allocated object) and=20
> checking in each iteration.
> Consider this max algorithm instead:
>
> template<typename Range>
> auto max(const Range& range) // possibly Range&& as well
> {
> for( auto v : range; auto m =3D v )
> if( m < v ) m=3Dv;
> for default // use whichever syntax you prefer
> return std::make_optional( m );
> for else
> return std::nullopt;
> }
>
> This also shows the requirement that any variables declared in *for*=20
> should be available in *for else* and *for default*.
>
> A completely generic syntax could have the following elements (let me kno=
w=20
> if any further), out of which we might choose which ones to support:
>
> - (precondition: this is handled by an initial *if* very well, probably=
=20
> no additional support needed)
> - (pre-fail: this is handled by an initial *if-else*, probably no=20
> additional support needed)
> - either:
> *- *init: this is the first parameter of the *for(;;)* syntax
> *- *head-cond: this is the second parameter of the *for(;;)* syntax
> *- *incr: this is the third parameter of the *for(;;)* syntax
> - postinit: this could be the 4th parameter of the above syntax, like=
=20
> *for(;;;)* or
> - range-init: this is the current *for( : )* syntax
> - postinit: this could be the second parameter of the above syntax,=
=20
> like=20
> *for(;;;)-* body, which we have now
> - continue statement(s) in body, which execute incr, then body iff=20
> tail-cond && head-cond.
> - break statement(s) in body, which go to tail-break
> - tail-cond: this is what we have with *do { } while( )*, in a generic=20
> (in theory, not necessarily in practice*) *framework these can be united
> - tails: zero or more distinct element of:
> - tail-break: executed when the loop finished due to *break*
> * - *tail-default: executed when we successfully entered at least once=
=20
> to the body of the loop (i.e., head-cond was true at least once) and ther=
e=20
> were no exceptions
> - tail-else: executed when head-cond was false for the first time
> - (tail-catch: this is handled very well by try-catch, probably no=20
> additional support needed)
>
> What do you think and how would you name each of these elements? Did I=20
> miss something, is there a better definition to come up with, should any=
=20
> points be refined?
>
> Thanks,
> -lorro
>
> 2016. j=C3=BAlius 17., vas=C3=A1rnap 21:00:37 UTC+2 id=C5=91pontban Derek=
Ross a=20
> k=C3=B6vetkez=C5=91t =C3=ADrta:
>>
>> Once the "if initializers" appear in C++17, you could almost get what yo=
u=20
>> want through a macro:
>>
>>
>> #define if_for(init,cond,incr) if(init ; cond)for(;cond;incr)
>> ...
>> if_for(int i =3D 0 ; i < n ; i ++)
>> {
>> ...etc...
>> }else{
>> cout << "cond was false\n";
>> }
>>
>>
>> Hmmm... maybe you could use "if for" as the syntax, which AFAIK is=20
>> currently illegal in C/C++.=20
>>
>> ----
>> Cheers,=20
>> Derek
>>
>> On Sunday, July 17, 2016 at 9:38:12 AM UTC-5, lorro (lorro@***) wrote:
>>>
>>> Many cases, specific handling is required when the body of the for loop=
=20
>>> was not executed. These include variable initializations which would've=
=20
>>> gotten value inside the loop, or throwing exceptions. Currently, these=
=20
>>> either need double-checking, which is inefficient, or copying the=20
>>> condition, which is error-prone, like:
>>>
>>> {
>>> *init;*
>>> if(*cond*)
>>> do
>>> {
>>> *body*
>>> incr;
>>> } while(*cond*)
>>> else
>>> *body-not-executed*
>>> }
>>>
>>> Note that this is still not exactly what we wanted as variables declare=
d=20
>>> in init are still visible in else branch. Any alternative requires=20
>>> double-checking or introducing a boolean variable that's updated in ini=
t=20
>>> and incr. What I'd recommend instead is allowing an else after for:
>>>
>>> for(*init*;* cond*; *incr*)
>>> *body*
>>> else
>>> =20
>>>
>>>
>>>
>>> *body-not-executedor,*for(* init *:* range *)
>>>
>>> * body*else
>>> *body-not-executed*
>>>
>>> As expected, body-not-executed should run iff cond has failed for the=
=20
>>> first time (or range was empty); in other words, if body was not execut=
ed.=20
>>> Optimizing compilers can unroll this easily and generate optimal code.=
=20
>>> Also, it does not clash with other language features as else is current=
ly=20
>>> only allowed after an if.=20
>>> What do you think?
>>>
>>
--=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/9f884d51-e98a-4ee5-ab2b-148ea9f4106e%40isocpp.or=
g.
------=_Part_51_1192582986.1468828080905
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">'This also shows the requirement that any variables de=
clared in <i>for</i> should be available in <i>for else</i> and <i>for defa=
ult</i>.'<br><br>Let me rephrase this, it holds for default and break, =
but certainly not for else<i>.</i><br><br>2016. j=C3=BAlius 18., h=C3=A9tf=
=C5=91 9:30:35 UTC+2 id=C5=91pontban szollos...@gmail.com a k=C3=B6vetkez=
=C5=91t =C3=ADrta:<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">This evaluates cond twice. Albeit, with double do-while, that's fe=
asible:<br><br>if(<i>init</i> ; <i>cond</i>) do { do <i>body</i> while(fals=
e); <i>incr</i>; } while(<i>cond</i>);<br><br>still not the most beautiful =
syntax...<br><br><br>---<br><br>Another thing, while we are here, that I mi=
ss is 'first-round initializer': that is, an initializer that's=
run <i>after</i> cond is checked. There are situations when the value you =
wish to initialize a variable to depends on the first value produced by the=
loop and no default constructor is available (or can be expected if it'=
;s a template type). If, furthermore, your range is such that you cannot &#=
39;go back' (i.e., iterator::operator++() invalidates and deallocates t=
he original iterator and it's value), and/or checking loop condition is=
very expensive, you might suddenly find yourself using <i>std::optional<=
;></i> (or pointer to a heap-allocated object) and checking in each iter=
ation.<br>Consider this max algorithm instead:<br><br>template<typename =
Range><br>auto max(const Range& range) // possibly Range&& a=
s well<br>{<br>=C2=A0=C2=A0=C2=A0 for( auto v : range; auto m =3D v )<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if( m < v ) m=3Dv;<br>=C2=A0=
=C2=A0=C2=A0 for default=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // use whichever syntax you prefer<br>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return std::make_optional( m );<br>=
=C2=A0=C2=A0=C2=A0 for else<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 r=
eturn std::nullopt;<br>}<br><br>This also shows the requirement that any va=
riables declared in <i>for</i> should be available in <i>for else</i> and <=
i>for default</i>.<br><br>A completely generic syntax could have the follow=
ing elements (let me know if any further), out of which we might choose whi=
ch ones to support:<br><br>- (precondition: this is handled by an initial <=
i>if</i> very well, probably no additional support needed)<br>- (pre-fail: =
this is handled by an initial <i>if-else</i>, probably no additional suppor=
t needed)<br>- either:<br>=C2=A0=C2=A0=C2=A0 <i>- </i>init: this is the fir=
st parameter of the <i>for(;;)</i> syntax<br>=C2=A0=C2=A0=C2=A0 <i>- </i>he=
ad-cond: this is the second parameter of the <i>for(;;)</i> syntax<br>=C2=
=A0=C2=A0=C2=A0 <i>- </i>incr: this is the third parameter of the <i>for(;;=
)</i> syntax<br>=C2=A0=C2=A0=C2=A0 - postinit: this could be the 4th parame=
ter of the above syntax, like <i>for(;;;)<br></i>=C2=A0 or<br>=C2=A0=C2=A0=
=C2=A0 - range-init: this is the current <i>for( : )</i> syntax<br>=C2=A0=
=C2=A0=C2=A0 - postinit: this could be the second parameter of the above sy=
ntax, like <i>for(;;;)<br>-</i> body, which we have now<br>=C2=A0=C2=A0=C2=
=A0 - continue statement(s) in body, which execute incr, then body iff tail=
-cond && head-cond.<br>=C2=A0=C2=A0=C2=A0 - break statement(s) in b=
ody, which go to tail-break<br>- tail-cond: this is what we have with <i>do=
{ } while( )</i>, in a generic (in theory, not necessarily in practice<i>)=
</i>framework these can be united<br>- tails: zero or more distinct elemen=
t of:<br>=C2=A0=C2=A0=C2=A0 - tail-break: executed when the loop finished d=
ue to <i>break</i><br><i>=C2=A0=C2=A0=C2=A0 - </i>tail-default: executed wh=
en we successfully entered at least once to the body of the loop (i.e., hea=
d-cond was true at least once) and there were no exceptions<br>=C2=A0=C2=A0=
=C2=A0 - tail-else: executed when head-cond was false for the first time<br=
>=C2=A0=C2=A0=C2=A0 - (tail-catch: this is handled very well by try-catch, =
probably no additional support needed)<br><br>What do you think and how wou=
ld you name each of these elements? Did I miss something, is there a better=
definition to come up with, should any points be refined?<br><br>Thanks,<b=
r>-lorro<br><i><br></i>2016. j=C3=BAlius 17., vas=C3=A1rnap 21:00:37 UTC+2 =
id=C5=91pontban Derek Ross a k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc=
solid;padding-left:1ex"><div dir=3D"ltr">Once the "if initializers&qu=
ot; appear in C++17, you could almost get what you want through a macro:<br=
><br><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,1=
87,187);border-style:solid;border-width:1px;word-wrap:break-word"><code><di=
v><span style=3D"color:#000"><br></span><span style=3D"color:#800">#define<=
/span><span style=3D"color:#000"> if_for</span><span style=3D"color:#660">(=
</span><span style=3D"color:#000">init</span><span style=3D"color:#660">,</=
span><span style=3D"color:#000">cond</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000">incr</span><span style=3D"color:#660">)</span=
><span style=3D"color:#000"> </span><span style=3D"color:#008">if</span><sp=
an style=3D"color:#660">(</span><span style=3D"color:#000">init </span><spa=
n style=3D"color:#660">;</span><span style=3D"color:#000"> cond</span><span=
style=3D"color:#660">)</span><span style=3D"color:#008">for</span><span st=
yle=3D"color:#660">(;</span><span style=3D"color:#000">cond</span><span sty=
le=3D"color:#660">;</span><span style=3D"color:#000">incr</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#660">...</span><span style=3D"color:#000"><br>=C2=A0 if_for</spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#008">int</span><=
span style=3D"color:#000"> i </span><span style=3D"color:#660">=3D</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#066">0</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"> i </span><span style=3D"color:#660"><</span><span style=
=3D"color:#000"> n </span><span style=3D"color:#660">;</span><span style=3D=
"color:#000"> i </span><span style=3D"color:#660">++)</span><span style=3D"=
color:#000"><br>=C2=A0 </span><span style=3D"color:#660">{</span><span styl=
e=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">...</s=
pan><span style=3D"color:#000">etc</span><span style=3D"color:#660">...</sp=
an><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#660">=
}</span><span style=3D"color:#008">else</span><span style=3D"color:#660">{<=
/span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 cout </span><span style=
=3D"color:#660"><<</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#080">"cond was false\n"</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"co=
lor:#660">}</span><span style=3D"color:#000"><br><br></span></div></code></=
div><br>Hmmm... maybe you could use "if for" as the syntax, which=
AFAIK is currently illegal in C/C++. <br><br>----<br>Cheers, <br>Derek<br>=
<br>On Sunday, July 17, 2016 at 9:38:12 AM UTC-5, lorro (lorro@***) 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">Many cases, specifi=
c handling is required when the body of the for loop was not executed. Thes=
e include variable initializations which would've gotten value inside t=
he loop, or throwing exceptions. Currently, these either need double-checki=
ng, which is inefficient, or copying the condition, which is error-prone, l=
ike:<br><span style=3D"font-family:courier new,monospace"><br>{<br>=C2=A0=
=C2=A0=C2=A0 <i>init;</i><br>=C2=A0=C2=A0=C2=A0 if(<i>cond</i>)<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 do<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0=
{<br>=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body</i><br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 incr;<br=
>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 } while(<i>cond</i>)<br>=C2=A0=C2=A0=C2=
=A0 else<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body-not-executed</i><br>}<=
br><br><span style=3D"font-family:arial,sans-serif">Note that this is still=
not exactly what we wanted as variables declared in init are still visible=
in else branch. Any alternative requires double-checking or introducing a =
boolean variable that's updated in init and incr. What I'd recommen=
d instead is allowing an else after for:<br><br><font face=3D"courier new,m=
onospace">for(<i>init</i>;<i> cond</i>; <i>incr</i>)<br>=C2=A0=C2=A0=C2=A0 =
<i>body</i><br>else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-executed<br><br><font=
face=3D"arial,sans-serif">or,<br><br></font></i><font face=3D"arial,sans-s=
erif"><font face=3D"courier new,monospace">for(</font></font><i><font face=
=3D"arial,sans-serif"><font face=3D"courier new,monospace"> init </font></f=
ont></i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospace=
">:</font></font><i><font face=3D"arial,sans-serif"><font face=3D"courier n=
ew,monospace"> range </font></font></i><font face=3D"arial,sans-serif"><fon=
t face=3D"courier new,monospace">)</font></font><i><font face=3D"arial,sans=
-serif"><font face=3D"courier new,monospace"><br>=C2=A0=C2=A0=C2=A0 body<br=
></font></font></i><font face=3D"arial,sans-serif"><font face=3D"courier ne=
w,monospace">else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-executed</i><br></font>=
</font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospa=
ce"></font></font><br></i><span style=3D"font-family:arial,sans-serif">As e=
xpected, body-not-executed should run iff cond has failed for the first tim=
e (or range was empty); in other words, if body was not executed. Optimizin=
g compilers can unroll this easily and generate optimal code. Also, it does=
not clash with other language features as else is currently only allowed a=
fter an if. <br>What do you think?<br><font face=3D"courier new,monospace">=
</font></span></font></span></span></div></blockquote></div></blockquote></=
div></blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9f884d51-e98a-4ee5-ab2b-148ea9f4106e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9f884d51-e98a-4ee5-ab2b-148ea9f4106e=
%40isocpp.org</a>.<br />
------=_Part_51_1192582986.1468828080905--
------=_Part_50_1888005697.1468828080905--
.
Author: szollosi.lorand@gmail.com
Date: Sat, 23 Jul 2016 14:57:04 -0700 (PDT)
Raw View
------=_Part_1795_1306647298.1469311024366
Content-Type: multipart/alternative;
boundary="----=_Part_1796_1205974179.1469311024367"
------=_Part_1796_1205974179.1469311024367
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
One more, somewhat orthogonal thing: do you think we could also consider *f=
or(=20
auto& x : **std::tuple<...>(...) )* with this proposal, or should that be a=
=20
separate one?
2016. j=C3=BAlius 18., h=C3=A9tf=C5=91 9:48:01 UTC+2 id=C5=91pontban szollo=
s...@gmail.com a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> 'This also shows the requirement that any variables declared in *for*=20
> should be available in *for else* and *for default*.'
>
> Let me rephrase this, it holds for default and break, but certainly not=
=20
> for else*.*
>
> 2016. j=C3=BAlius 18., h=C3=A9tf=C5=91 9:30:35 UTC+2 id=C5=91pontban szol=
los...@gmail.com a=20
> k=C3=B6vetkez=C5=91t =C3=ADrta:
>>
>> This evaluates cond twice. Albeit, with double do-while, that's feasible=
:
>>
>> if(*init* ; *cond*) do { do *body* while(false); *incr*; } while(*cond*)=
;
>>
>> still not the most beautiful syntax...
>>
>>
>> ---
>>
>> Another thing, while we are here, that I miss is 'first-round=20
>> initializer': that is, an initializer that's run *after* cond is=20
>> checked. There are situations when the value you wish to initialize a=20
>> variable to depends on the first value produced by the loop and no defau=
lt=20
>> constructor is available (or can be expected if it's a template type). I=
f,=20
>> furthermore, your range is such that you cannot 'go back' (i.e.,=20
>> iterator::operator++() invalidates and deallocates the original iterator=
=20
>> and it's value), and/or checking loop condition is very expensive, you=
=20
>> might suddenly find yourself using *std::optional<>* (or pointer to a=20
>> heap-allocated object) and checking in each iteration.
>> Consider this max algorithm instead:
>>
>> template<typename Range>
>> auto max(const Range& range) // possibly Range&& as well
>> {
>> for( auto v : range; auto m =3D v )
>> if( m < v ) m=3Dv;
>> for default // use whichever syntax you prefer
>> return std::make_optional( m );
>> for else
>> return std::nullopt;
>> }
>>
>> This also shows the requirement that any variables declared in *for*=20
>> should be available in *for else* and *for default*.
>>
>> A completely generic syntax could have the following elements (let me=20
>> know if any further), out of which we might choose which ones to support=
:
>>
>> - (precondition: this is handled by an initial *if* very well, probably=
=20
>> no additional support needed)
>> - (pre-fail: this is handled by an initial *if-else*, probably no=20
>> additional support needed)
>> - either:
>> *- *init: this is the first parameter of the *for(;;)* syntax
>> *- *head-cond: this is the second parameter of the *for(;;)* syntax
>> *- *incr: this is the third parameter of the *for(;;)* syntax
>> - postinit: this could be the 4th parameter of the above syntax, lik=
e=20
>> *for(;;;)* or
>> - range-init: this is the current *for( : )* syntax
>> - postinit: this could be the second parameter of the above syntax,=
=20
>> like=20
>> *for(;;;)-* body, which we have now
>> - continue statement(s) in body, which execute incr, then body iff=
=20
>> tail-cond && head-cond.
>> - break statement(s) in body, which go to tail-break
>> - tail-cond: this is what we have with *do { } while( )*, in a generic=
=20
>> (in theory, not necessarily in practice*) *framework these can be united
>> - tails: zero or more distinct element of:
>> - tail-break: executed when the loop finished due to *break*
>> * - *tail-default: executed when we successfully entered at least=20
>> once to the body of the loop (i.e., head-cond was true at least once) an=
d=20
>> there were no exceptions
>> - tail-else: executed when head-cond was false for the first time
>> - (tail-catch: this is handled very well by try-catch, probably no=
=20
>> additional support needed)
>>
>> What do you think and how would you name each of these elements? Did I=
=20
>> miss something, is there a better definition to come up with, should any=
=20
>> points be refined?
>>
>> Thanks,
>> -lorro
>>
>> 2016. j=C3=BAlius 17., vas=C3=A1rnap 21:00:37 UTC+2 id=C5=91pontban Dere=
k Ross a=20
>> k=C3=B6vetkez=C5=91t =C3=ADrta:
>>>
>>> Once the "if initializers" appear in C++17, you could almost get what=
=20
>>> you want through a macro:
>>>
>>>
>>> #define if_for(init,cond,incr) if(init ; cond)for(;cond;incr)
>>> ...
>>> if_for(int i =3D 0 ; i < n ; i ++)
>>> {
>>> ...etc...
>>> }else{
>>> cout << "cond was false\n";
>>> }
>>>
>>>
>>> Hmmm... maybe you could use "if for" as the syntax, which AFAIK is=20
>>> currently illegal in C/C++.=20
>>>
>>> ----
>>> Cheers,=20
>>> Derek
>>>
>>> On Sunday, July 17, 2016 at 9:38:12 AM UTC-5, lorro (lorro@***) wrote:
>>>>
>>>> Many cases, specific handling is required when the body of the for loo=
p=20
>>>> was not executed. These include variable initializations which would'v=
e=20
>>>> gotten value inside the loop, or throwing exceptions. Currently, these=
=20
>>>> either need double-checking, which is inefficient, or copying the=20
>>>> condition, which is error-prone, like:
>>>>
>>>> {
>>>> *init;*
>>>> if(*cond*)
>>>> do
>>>> {
>>>> *body*
>>>> incr;
>>>> } while(*cond*)
>>>> else
>>>> *body-not-executed*
>>>> }
>>>>
>>>> Note that this is still not exactly what we wanted as variables=20
>>>> declared in init are still visible in else branch. Any alternative req=
uires=20
>>>> double-checking or introducing a boolean variable that's updated in in=
it=20
>>>> and incr. What I'd recommend instead is allowing an else after for:
>>>>
>>>> for(*init*;* cond*; *incr*)
>>>> *body*
>>>> else
>>>> =20
>>>>
>>>>
>>>>
>>>> *body-not-executedor,*for(* init *:* range *)
>>>>
>>>> * body*else
>>>> *body-not-executed*
>>>>
>>>> As expected, body-not-executed should run iff cond has failed for the=
=20
>>>> first time (or range was empty); in other words, if body was not execu=
ted.=20
>>>> Optimizing compilers can unroll this easily and generate optimal code.=
=20
>>>> Also, it does not clash with other language features as else is curren=
tly=20
>>>> only allowed after an if.=20
>>>> What do you think?
>>>>
>>>
--=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/209d505b-f659-4719-ba93-f319c947053e%40isocpp.or=
g.
------=_Part_1796_1205974179.1469311024367
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">One more, somewhat orthogonal thing: do you think we could=
also consider <i>for( auto& x : </i><i>std::tuple<...>(...) )</i=
> with this proposal, or should that be a separate one?<br><br>2016. j=C3=
=BAlius 18., h=C3=A9tf=C5=91 9:48:01 UTC+2 id=C5=91pontban szollos...@gmail=
..com a k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote class=3D"gmail_quote" sty=
le=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left=
: 1ex;"><div dir=3D"ltr">'This also shows the requirement that any vari=
ables declared in <i>for</i> should be available in <i>for else</i> and <i>=
for default</i>.'<br><br>Let me rephrase this, it holds for default and=
break, but certainly not for else<i>.</i><br><br>2016. j=C3=BAlius 18., h=
=C3=A9tf=C5=91 9:30:35 UTC+2 id=C5=91pontban <a>szollos...@gmail.com</a> a =
k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div=
dir=3D"ltr">This evaluates cond twice. Albeit, with double do-while, that&=
#39;s feasible:<br><br>if(<i>init</i> ; <i>cond</i>) do { do <i>body</i> wh=
ile(false); <i>incr</i>; } while(<i>cond</i>);<br><br>still not the most be=
autiful syntax...<br><br><br>---<br><br>Another thing, while we are here, t=
hat I miss is 'first-round initializer': that is, an initializer th=
at's run <i>after</i> cond is checked. There are situations when the va=
lue you wish to initialize a variable to depends on the first value produce=
d by the loop and no default constructor is available (or can be expected i=
f it's a template type). If, furthermore, your range is such that you c=
annot 'go back' (i.e., iterator::operator++() invalidates and deall=
ocates the original iterator and it's value), and/or checking loop cond=
ition is very expensive, you might suddenly find yourself using <i>std::opt=
ional<></i> (or pointer to a heap-allocated object) and checking in e=
ach iteration.<br>Consider this max algorithm instead:<br><br>template<t=
ypename Range><br>auto max(const Range& range) // possibly Range&=
;& as well<br>{<br>=C2=A0=C2=A0=C2=A0 for( auto v : range; auto m =3D v=
)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if( m < v ) m=3Dv;<br>=
=C2=A0=C2=A0=C2=A0 for default=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // use whichever syntax you prefer<=
br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return std::make_optional( m =
);<br>=C2=A0=C2=A0=C2=A0 for else<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 return std::nullopt;<br>}<br><br>This also shows the requirement tha=
t any variables declared in <i>for</i> should be available in <i>for else</=
i> and <i>for default</i>.<br><br>A completely generic syntax could have th=
e following elements (let me know if any further), out of which we might ch=
oose which ones to support:<br><br>- (precondition: this is handled by an i=
nitial <i>if</i> very well, probably no additional support needed)<br>- (pr=
e-fail: this is handled by an initial <i>if-else</i>, probably no additiona=
l support needed)<br>- either:<br>=C2=A0=C2=A0=C2=A0 <i>- </i>init: this is=
the first parameter of the <i>for(;;)</i> syntax<br>=C2=A0=C2=A0=C2=A0 <i>=
- </i>head-cond: this is the second parameter of the <i>for(;;)</i> syntax<=
br>=C2=A0=C2=A0=C2=A0 <i>- </i>incr: this is the third parameter of the <i>=
for(;;)</i> syntax<br>=C2=A0=C2=A0=C2=A0 - postinit: this could be the 4th =
parameter of the above syntax, like <i>for(;;;)<br></i>=C2=A0 or<br>=C2=A0=
=C2=A0=C2=A0 - range-init: this is the current <i>for( : )</i> syntax<br>=
=C2=A0=C2=A0=C2=A0 - postinit: this could be the second parameter of the ab=
ove syntax, like <i>for(;;;)<br>-</i> body, which we have now<br>=C2=A0=C2=
=A0=C2=A0 - continue statement(s) in body, which execute incr, then body if=
f tail-cond && head-cond.<br>=C2=A0=C2=A0=C2=A0 - break statement(s=
) in body, which go to tail-break<br>- tail-cond: this is what we have with=
<i>do { } while( )</i>, in a generic (in theory, not necessarily in practi=
ce<i>) </i>framework these can be united<br>- tails: zero or more distinct =
element of:<br>=C2=A0=C2=A0=C2=A0 - tail-break: executed when the loop fini=
shed due to <i>break</i><br><i>=C2=A0=C2=A0=C2=A0 - </i>tail-default: execu=
ted when we successfully entered at least once to the body of the loop (i.e=
.., head-cond was true at least once) and there were no exceptions<br>=C2=A0=
=C2=A0=C2=A0 - tail-else: executed when head-cond was false for the first t=
ime<br>=C2=A0=C2=A0=C2=A0 - (tail-catch: this is handled very well by try-c=
atch, probably no additional support needed)<br><br>What do you think and h=
ow would you name each of these elements? Did I miss something, is there a =
better definition to come up with, should any points be refined?<br><br>Tha=
nks,<br>-lorro<br><i><br></i>2016. j=C3=BAlius 17., vas=C3=A1rnap 21:00:37 =
UTC+2 id=C5=91pontban Derek Ross a k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquo=
te class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr">Once the "if initializ=
ers" appear in C++17, you could almost get what you want through a mac=
ro:<br><br><div style=3D"background-color:rgb(250,250,250);border-color:rgb=
(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><co=
de><div><span style=3D"color:#000"><br></span><span style=3D"color:#800">#d=
efine</span><span style=3D"color:#000"> if_for</span><span style=3D"color:#=
660">(</span><span style=3D"color:#000">init</span><span style=3D"color:#66=
0">,</span><span style=3D"color:#000">cond</span><span style=3D"color:#660"=
>,</span><span style=3D"color:#000">incr</span><span style=3D"color:#660">)=
</span><span style=3D"color:#000"> </span><span style=3D"color:#008">if</sp=
an><span style=3D"color:#660">(</span><span style=3D"color:#000">init </spa=
n><span style=3D"color:#660">;</span><span style=3D"color:#000"> cond</span=
><span style=3D"color:#660">)</span><span style=3D"color:#008">for</span><s=
pan style=3D"color:#660">(;</span><span style=3D"color:#000">cond</span><sp=
an style=3D"color:#660">;</span><span style=3D"color:#000">incr</span><span=
style=3D"color:#660">)</span><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#660">...</span><span style=3D"color:#000"><br>=C2=A0 if_for<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#008">int</sp=
an><span style=3D"color:#000"> i </span><span style=3D"color:#660">=3D</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#066">0</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">;</span><span st=
yle=3D"color:#000"> i </span><span style=3D"color:#660"><</span><span st=
yle=3D"color:#000"> n </span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"> i </span><span style=3D"color:#660">++)</span><span style=
=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#660">{</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">..=
..</span><span style=3D"color:#000">etc</span><span style=3D"color:#660">...=
</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#6=
60">}</span><span style=3D"color:#008">else</span><span style=3D"color:#660=
">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 cout </span><span st=
yle=3D"color:#660"><<</span><span style=3D"color:#000"> </span><span =
style=3D"color:#080">"cond was false\n"</span><span style=3D"colo=
r:#660">;</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D=
"color:#660">}</span><span style=3D"color:#000"><br><br></span></div></code=
></div><br>Hmmm... maybe you could use "if for" as the syntax, wh=
ich AFAIK is currently illegal in C/C++. <br><br>----<br>Cheers, <br>Derek<=
br><br>On Sunday, July 17, 2016 at 9:38:12 AM UTC-5, lorro (lorro@***) wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bor=
der-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Many cases, spec=
ific handling is required when the body of the for loop was not executed. T=
hese include variable initializations which would've gotten value insid=
e the loop, or throwing exceptions. Currently, these either need double-che=
cking, which is inefficient, or copying the condition, which is error-prone=
, like:<br><span style=3D"font-family:courier new,monospace"><br>{<br>=C2=
=A0=C2=A0=C2=A0 <i>init;</i><br>=C2=A0=C2=A0=C2=A0 if(<i>cond</i>)<br>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 do<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=
=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body</i><br=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 incr;<b=
r>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 } while(<i>cond</i>)<br>=C2=A0=C2=A0=C2=
=A0 else<br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 <i>body-not-executed</i><br>}<=
br><br><span style=3D"font-family:arial,sans-serif">Note that this is still=
not exactly what we wanted as variables declared in init are still visible=
in else branch. Any alternative requires double-checking or introducing a =
boolean variable that's updated in init and incr. What I'd recommen=
d instead is allowing an else after for:<br><br><font face=3D"courier new,m=
onospace">for(<i>init</i>;<i> cond</i>; <i>incr</i>)<br>=C2=A0=C2=A0=C2=A0 =
<i>body</i><br>else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-executed<br><br><font=
face=3D"arial,sans-serif">or,<br><br></font></i><font face=3D"arial,sans-s=
erif"><font face=3D"courier new,monospace">for(</font></font><i><font face=
=3D"arial,sans-serif"><font face=3D"courier new,monospace"> init </font></f=
ont></i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospace=
">:</font></font><i><font face=3D"arial,sans-serif"><font face=3D"courier n=
ew,monospace"> range </font></font></i><font face=3D"arial,sans-serif"><fon=
t face=3D"courier new,monospace">)</font></font><i><font face=3D"arial,sans=
-serif"><font face=3D"courier new,monospace"><br>=C2=A0=C2=A0=C2=A0 body<br=
></font></font></i><font face=3D"arial,sans-serif"><font face=3D"courier ne=
w,monospace">else<br>=C2=A0=C2=A0=C2=A0 <i>body-not-executed</i><br></font>=
</font><i><font face=3D"arial,sans-serif"><font face=3D"courier new,monospa=
ce"></font></font><br></i><span style=3D"font-family:arial,sans-serif">As e=
xpected, body-not-executed should run iff cond has failed for the first tim=
e (or range was empty); in other words, if body was not executed. Optimizin=
g compilers can unroll this easily and generate optimal code. Also, it does=
not clash with other language features as else is currently only allowed a=
fter an if. <br>What do you think?<br><font face=3D"courier new,monospace">=
</font></span></font></span></span></div></blockquote></div></blockquote></=
div></blockquote></div></blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/209d505b-f659-4719-ba93-f319c947053e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/209d505b-f659-4719-ba93-f319c947053e=
%40isocpp.org</a>.<br />
------=_Part_1796_1205974179.1469311024367--
------=_Part_1795_1306647298.1469311024366--
.
Author: "D. B." <db0451@gmail.com>
Date: Sat, 23 Jul 2016 23:04:38 +0100
Raw View
--089e0122ea38c68446053854bc22
Content-Type: text/plain; charset=UTF-8
That sounds completely unrelated. But I guess I should check whether my
inferences are accurate. What would it do? act like a template by creating
a different loop body for each type of element, where x has a different
type each time? I think that would need some different syntax, e.g.
"template<T> for (T&& x: tuple)", as just using the same syntax wouldn't
make it clear enough that the type changes each time.
--
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/CACGiwhH%3DCVKe4uzqcWbFKk9%3DM8dF2q%3DGmY8foh_6mYh55r6A7Q%40mail.gmail.com.
--089e0122ea38c68446053854bc22
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">That sounds completely unrelated. But I guess I should che=
ck whether my inferences are accurate. What would it do? act like a templat=
e by creating a different loop body for each type of element, where x has a=
different type each time? I think that would need some different syntax, e=
..g. "template<T> for (T&& x: tuple)", as just using=
the same syntax wouldn't make it clear enough that the type changes ea=
ch time.<br></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CACGiwhH%3DCVKe4uzqcWbFKk9%3DM8dF2q%3=
DGmY8foh_6mYh55r6A7Q%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhH%3D=
CVKe4uzqcWbFKk9%3DM8dF2q%3DGmY8foh_6mYh55r6A7Q%40mail.gmail.com</a>.<br />
--089e0122ea38c68446053854bc22--
.
Author: "D. B." <db0451@gmail.com>
Date: Sat, 23 Jul 2016 23:06:31 +0100
Raw View
--001a114ba3908da039053854c38f
Content-Type: text/plain; charset=UTF-8
....but then (and again, this assumes I'm inferring its purpose correctly) I
don't know whether that pattern is common enough to be considered for a
syntax extension, nor whether the existing ways to roll-your-own via
variadic templates are difficult enough to justify 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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhFhMX2vQLuiKTjJ6PmfYXHDZYCHbDc0nEwQQiE3JqbEvg%40mail.gmail.com.
--001a114ba3908da039053854c38f
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">...but then (and again, this assumes I'm inferring its=
purpose correctly) I don't know whether that pattern is common enough =
to be considered for a syntax extension, nor whether the existing ways to r=
oll-your-own via variadic templates are difficult enough to justify it.<br>=
</div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CACGiwhFhMX2vQLuiKTjJ6PmfYXHDZYCHbDc0=
nEwQQiE3JqbEvg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhFhMX2vQLui=
KTjJ6PmfYXHDZYCHbDc0nEwQQiE3JqbEvg%40mail.gmail.com</a>.<br />
--001a114ba3908da039053854c38f--
.
Author: szollosi.lorand@gmail.com
Date: Sat, 23 Jul 2016 15:19:17 -0700 (PDT)
Raw View
------=_Part_260_1988005403.1469312357713
Content-Type: multipart/alternative;
boundary="----=_Part_261_2086456436.1469312357713"
------=_Part_261_2086456436.1469312357713
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
tuple-for is asked by novice-to-medium-level programmers all the time. Yes,=
=20
it's a templated body. I didn't write *template<typename T> for( T ... ) *a=
s=20
we have generic lambdas now, but I'm okay with that syntax as well. I'm=20
aware of the 'templated for_each pattern', but I find it unnecessarily=20
complicated (to explain, mainly) for such a trivial task. Also, I'm hoping=
=20
to see 'heterogeneous container' visitors (think of boost::fusion) and=20
*variant* visitors (similarly to *for* over *optional*).
Or am I missing something trivial that can already do these, perhaps with=
=20
some library code?
2016. j=C3=BAlius 24., vas=C3=A1rnap 0:06:34 UTC+2 id=C5=91pontban D. B. a =
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> ...but then (and again, this assumes I'm inferring its purpose correctly)=
=20
> I don't know whether that pattern is common enough to be considered for a=
=20
> syntax extension, nor whether the existing ways to roll-your-own via=20
> variadic templates are difficult enough to justify it.
>
--=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/7cd1c269-d92f-4145-8af9-95d771682391%40isocpp.or=
g.
------=_Part_261_2086456436.1469312357713
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">tuple-for is asked by novice-to-medium-level programmers a=
ll the time. Yes, it's a templated body. I didn't write <i>template=
<typename T> for( T ... ) </i>as we have generic lambdas now, but I&#=
39;m okay with that syntax as well. I'm aware of the 'templated for=
_each pattern', but I find it unnecessarily complicated (to explain, ma=
inly) for such a trivial task. Also, I'm hoping to see 'heterogeneo=
us container' visitors (think of boost::fusion) and <i>variant</i> visi=
tors (similarly to <i>for</i> over <i>optional</i>).<br>Or am I missing som=
ething trivial that can already do these, perhaps with some library code?<b=
r><br>2016. j=C3=BAlius 24., vas=C3=A1rnap 0:06:34 UTC+2 id=C5=91pontban D.=
B. a k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left:=
1ex;"><div dir=3D"ltr">...but then (and again, this assumes I'm inferr=
ing its purpose correctly) I don't know whether that pattern is common =
enough to be considered for a syntax extension, nor whether the existing wa=
ys to roll-your-own via variadic templates are difficult enough to justify =
it.<br></div>
</blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7cd1c269-d92f-4145-8af9-95d771682391%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7cd1c269-d92f-4145-8af9-95d771682391=
%40isocpp.org</a>.<br />
------=_Part_261_2086456436.1469312357713--
------=_Part_260_1988005403.1469312357713--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 23 Jul 2016 16:00:18 -0700 (PDT)
Raw View
------=_Part_515_1531160374.1469314818557
Content-Type: multipart/alternative;
boundary="----=_Part_516_2026845548.1469314818557"
------=_Part_516_2026845548.1469314818557
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Saturday, July 23, 2016 at 6:19:18 PM UTC-4, szollos...@gmail.com wrote:
>
> tuple-for is asked by novice-to-medium-level programmers all the time.=20
> Yes, it's a templated body. I didn't write *template<typename T> for( T=
=20
> ... ) *as we have generic lambdas now, but I'm okay with that syntax as=
=20
> well. I'm aware of the 'templated for_each pattern', but I find it=20
> unnecessarily complicated (to explain, mainly) for such a trivial task.=
=20
> Also, I'm hoping to see 'heterogeneous container' visitors (think of=20
> boost::fusion) and *variant* visitors (similarly to *for* over *optional*
> ).
> Or am I missing something trivial that can already do these, perhaps with=
=20
> some library code?
>
The fact of the matter is, I don't want to see tuple-for. Or language-level=
=20
visitation. I would much rather see that feature that we discussed earlier=
=20
that would allow you to transform a tuple (or tuple-like type) into a=20
parameter pack, which you could then unpack like any other.
That'd be far more useful than a mere tuple-for. And a *lot* easier to=20
standardize.
But as previously pointed out, this is all *way* off-topic here.
2016. j=C3=BAlius 24., vas=C3=A1rnap 0:06:34 UTC+2 id=C5=91pontban D. B. a =
k=C3=B6vetkez=C5=91t =C3=ADrta:
>>
>> ...but then (and again, this assumes I'm inferring its purpose correctly=
)=20
>> I don't know whether that pattern is common enough to be considered for =
a=20
>> syntax extension, nor whether the existing ways to roll-your-own via=20
>> variadic templates are difficult enough to justify it.
>>
>
To be fair, it's not easy to write code that will be executed for each=20
element in a tuple. It represents a hole in doing things with tuples.
It's easy to build a tuple. It's easy to pass tuples around. It's easy to=
=20
get a single element from a tuple. These basic uses of a tuple do not=20
require complex metaprogramming techniques.
But to perform an act, even if it's just a single function call, on each=20
element requires metaprogramming. Granted, performing an act for each=20
member of a struct requires... well, it requires macros & metaprogramming,=
=20
so it's much worse. But with a tuple, it seems (from the perspective of a=
=20
novice) to be such a simple thing.
Hence my desire for tuple-to-pack transformations. That's a simple thing=20
that they can understand.
--=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/8056dc6a-5961-4a5c-9efe-f53a5580cb98%40isocpp.or=
g.
------=_Part_516_2026845548.1469314818557
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, July 23, 2016 at 6:19:18 PM UTC-4, szollos...=
@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">tuple-for is asked by novice-to-medium-level programmers all the time. =
Yes, it's a templated body. I didn't write <i>template<typename =
T> for( T ... ) </i>as we have generic lambdas now, but I'm okay wit=
h that syntax as well. I'm aware of the 'templated for_each pattern=
', but I find it unnecessarily complicated (to explain, mainly) for suc=
h a trivial task. Also, I'm hoping to see 'heterogeneous container&=
#39; visitors (think of boost::fusion) and <i>variant</i> visitors (similar=
ly to <i>for</i> over <i>optional</i>).<br>Or am I missing something trivia=
l that can already do these, perhaps with some library code?<br></div></blo=
ckquote><div><br>The fact of the matter is, I don't want to see tuple-f=
or. Or language-level visitation. I would much rather see that feature that=
we discussed earlier that would allow you to transform a tuple (or tuple-l=
ike type) into a parameter pack, which you could then unpack like any other=
..<br><br>That'd be far more useful than a mere tuple-for. And a <i>lot<=
/i> easier to standardize.<br><br>But as previously pointed out, this is al=
l <i>way</i> off-topic here.<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 dir=3D"ltr">2016. j=C3=BAlius 24., vas=C3=A1rnap 0:06:34 U=
TC+2 id=C5=91pontban D. B. a k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc=
solid;padding-left:1ex"><div dir=3D"ltr">...but then (and again, this assu=
mes I'm inferring its purpose correctly) I don't know whether that =
pattern is common enough to be considered for a syntax extension, nor wheth=
er the existing ways to roll-your-own via variadic templates are difficult =
enough to justify it.<br></div></blockquote></div></blockquote><div><br>To =
be fair, it's not easy to write code that will be executed for each ele=
ment in a tuple. It represents a hole in doing things with tuples.<br><br>I=
t's easy to build a tuple. It's easy to pass tuples around. It'=
s easy to get a single element from a tuple. These basic uses of a tuple do=
not require complex metaprogramming techniques.<br><br>But to perform an a=
ct, even if it's just a single function call, on each element requires =
metaprogramming. Granted, performing an act for each member of a struct req=
uires... well, it requires macros & metaprogramming, so it's much w=
orse. But with a tuple, it seems (from the perspective of a novice) to be s=
uch a simple thing.<br><br>Hence my desire for tuple-to-pack transformation=
s. That's a simple thing that they can understand.<br></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/8056dc6a-5961-4a5c-9efe-f53a5580cb98%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8056dc6a-5961-4a5c-9efe-f53a5580cb98=
%40isocpp.org</a>.<br />
------=_Part_516_2026845548.1469314818557--
------=_Part_515_1531160374.1469314818557--
.
Author: "D. B." <db0451@gmail.com>
Date: Sun, 24 Jul 2016 00:12:54 +0100
Raw View
--94eb2c0d7c60f56322053855b06c
Content-Type: text/plain; charset=UTF-8
On Sun, Jul 24, 2016 at 12:00 AM, Nicol Bolas <jmckesson@gmail.com> wrote:
>
> To be fair, it's not easy to write code that will be executed for each
> element in a tuple. It represents a hole in doing things with tuples.
>
> It's easy to build a tuple. It's easy to pass tuples around. It's easy to
> get a single element from a tuple. These basic uses of a tuple do not
> require complex metaprogramming techniques.
>
> But to perform an act, even if it's just a single function call, on each
> element requires metaprogramming. Granted, performing an act for each
> member of a struct requires... well, it requires macros & metaprogramming,
> so it's much worse. But with a tuple, it seems (from the perspective of a
> novice) to be such a simple thing.
>
> Hence my desire for tuple-to-pack transformations. That's a simple thing
> that they can understand.
>
Yeah, that sounds preferable, especially by using existing (if, at least
from what I've seen, a bit underused) syntax, rather than requiring another
new set, which would be redundant.
Maybe I was thinking of something else when I implied it wasn't that
difficult... a quick scan shows it looks rather thorny.
BUT! This looks promising if accurate (not tested it myself):
http://stackoverflow.com/a/37100197/2757035
Sure, not an immediately intuitive syntax, but makes sense after a few
seconds, and way better than the alternatives anyhow.
--
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/CACGiwhHOj8oy7XxzfoWWcgup--zpcMFZFGSi3N1z%2BXGvSvj8ug%40mail.gmail.com.
--94eb2c0d7c60f56322053855b06c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
un, Jul 24, 2016 at 12:00 AM, Nicol Bolas <span dir=3D"ltr"><<a target=
=3D"_blank" href=3D"mailto:jmckesson@gmail.com">jmckesson@gmail.com</a>>=
</span> wrote:<blockquote style=3D"margin:0px 0px 0px 0.8ex;border-left:1px=
solid rgb(204,204,204);padding-left:1ex" class=3D"gmail_quote"><div dir=3D=
"ltr"><div>To be fair, it's not easy to write code that will be execute=
d for each element in a tuple. It represents a hole in doing things with tu=
ples.<br><br>It's easy to build a tuple. It's easy to pass tuples a=
round. It's easy to get a single element from a tuple. These basic uses=
of a tuple do not require complex metaprogramming techniques.<br><br>But t=
o perform an act, even if it's just a single function call, on each ele=
ment requires metaprogramming. Granted, performing an act for each member o=
f a struct requires... well, it requires macros & metaprogramming, so i=
t's much worse. But with a tuple, it seems (from the perspective of a n=
ovice) to be such a simple thing.<br><br>Hence my desire for tuple-to-pack =
transformations. That's a simple thing that they can understand.<br></d=
iv></div></blockquote><div><br></div><div>Yeah, that sounds preferable, esp=
ecially by using existing (if, at least from what I've seen, a bit unde=
rused) syntax, rather than requiring another new set, which would be redund=
ant.<br><br></div><div>Maybe I was thinking of something else when I implie=
d it wasn't that difficult... a=C2=A0 quick scan shows it looks rather =
thorny.<br><br></div><div>BUT! This looks promising if accurate (not tested=
it myself): <a href=3D"http://stackoverflow.com/a/37100197/2757035">http:/=
/stackoverflow.com/a/37100197/2757035</a><br></div><div>Sure, not an immedi=
ately intuitive syntax, but makes sense after a few seconds, and way better=
than the alternatives anyhow.<br><br></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" 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/CACGiwhHOj8oy7XxzfoWWcgup--zpcMFZFGSi=
3N1z%2BXGvSvj8ug%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhHOj8oy7X=
xzfoWWcgup--zpcMFZFGSi3N1z%2BXGvSvj8ug%40mail.gmail.com</a>.<br />
--94eb2c0d7c60f56322053855b06c--
.
Author: szollosi.lorand@gmail.com
Date: Mon, 25 Jul 2016 07:17:04 -0700 (PDT)
Raw View
------=_Part_3167_275017417.1469456224236
Content-Type: multipart/alternative;
boundary="----=_Part_3168_199522804.1469456224236"
------=_Part_3168_199522804.1469456224236
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Ok, so perhaps we can set aside tuple_for for this one. (I'd also like to=
=20
see better tuple <-> params & init list interwork, but that deserves a=20
separate, longer thread).
Do you think there's anything to add to the *for* & *while* before we make=
=20
a draft?
Also - do you perhaps have any thoughts on why the previous draft on *for*=
=20
didn't make it and how to improve so that this one does?
Thanks,
-lorro
2016. j=C3=BAlius 24., vas=C3=A1rnap 1:12:57 UTC+2 id=C5=91pontban D. B. a =
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> On Sun, Jul 24, 2016 at 12:00 AM, Nicol Bolas <jmck...@gmail.com=20
> <javascript:>> wrote:
>>
>> To be fair, it's not easy to write code that will be executed for each=
=20
>> element in a tuple. It represents a hole in doing things with tuples.
>>
>> It's easy to build a tuple. It's easy to pass tuples around. It's easy t=
o=20
>> get a single element from a tuple. These basic uses of a tuple do not=20
>> require complex metaprogramming techniques.
>>
>> But to perform an act, even if it's just a single function call, on each=
=20
>> element requires metaprogramming. Granted, performing an act for each=20
>> member of a struct requires... well, it requires macros & metaprogrammin=
g,=20
>> so it's much worse. But with a tuple, it seems (from the perspective of =
a=20
>> novice) to be such a simple thing.
>>
>> Hence my desire for tuple-to-pack transformations. That's a simple thing=
=20
>> that they can understand.
>>
>
> Yeah, that sounds preferable, especially by using existing (if, at least=
=20
> from what I've seen, a bit underused) syntax, rather than requiring anoth=
er=20
> new set, which would be redundant.
>
> Maybe I was thinking of something else when I implied it wasn't that=20
> difficult... a quick scan shows it looks rather thorny.
>
> BUT! This looks promising if accurate (not tested it myself):=20
> http://stackoverflow.com/a/37100197/2757035
> Sure, not an immediately intuitive syntax, but makes sense after a few=20
> seconds, and way better than the alternatives anyhow.
>
>
--=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/77a0b930-c6dd-4fc0-8327-c38640d76392%40isocpp.or=
g.
------=_Part_3168_199522804.1469456224236
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Ok, so perhaps we can set aside tuple_for for this one. (I=
'd also like to see better tuple <-> params & init list inter=
work, but that deserves a separate, longer thread).<br>Do you think there&#=
39;s anything to add to the <i>for</i> & <i>while</i> before we make a =
draft?<br>Also - do you perhaps have any thoughts on why the previous draft=
on <i>for</i> didn't make it and how to improve so that this one does?=
<br><br>Thanks,<br>-lorro<br><br>2016. j=C3=BAlius 24., vas=C3=A1rnap 1:12:=
57 UTC+2 id=C5=91pontban D. B. a k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote=
class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1=
px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail=
_quote">On Sun, Jul 24, 2016 at 12:00 AM, Nicol Bolas <span dir=3D"ltr"><=
;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"aWv5SCE=
GBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';re=
turn true;" onclick=3D"this.href=3D'javascript:';return true;">jmck=
....@gmail.com</a>></span> wrote:<blockquote style=3D"margin:0px 0px 0px =
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class=3D"gma=
il_quote"><div dir=3D"ltr"><div>To be fair, it's not easy to write code=
that will be executed for each element in a tuple. It represents a hole in=
doing things with tuples.<br><br>It's easy to build a tuple. It's =
easy to pass tuples around. It's easy to get a single element from a tu=
ple. These basic uses of a tuple do not require complex metaprogramming tec=
hniques.<br><br>But to perform an act, even if it's just a single funct=
ion call, on each element requires metaprogramming. Granted, performing an =
act for each member of a struct requires... well, it requires macros & =
metaprogramming, so it's much worse. But with a tuple, it seems (from t=
he perspective of a novice) to be such a simple thing.<br><br>Hence my desi=
re for tuple-to-pack transformations. That's a simple thing that they c=
an understand.<br></div></div></blockquote><div><br></div><div>Yeah, that s=
ounds preferable, especially by using existing (if, at least from what I=
9;ve seen, a bit underused) syntax, rather than requiring another new set, =
which would be redundant.<br><br></div><div>Maybe I was thinking of somethi=
ng else when I implied it wasn't that difficult... a=C2=A0 quick scan s=
hows it looks rather thorny.<br><br></div><div>BUT! This looks promising if=
accurate (not tested it myself): <a href=3D"http://stackoverflow.com/a/371=
00197/2757035" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=
=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fstackoverflow.com%2Fa%2=
F37100197%2F2757035\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFe3ZZzNWldPoUcE=
g4GBWRmQBcwaA';return true;" onclick=3D"this.href=3D'http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fstackoverflow.com%2Fa%2F37100197%2F2757035\x2=
6sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFe3ZZzNWldPoUcEg4GBWRmQBcwaA';ret=
urn true;">http://stackoverflow.com/a/<wbr>37100197/2757035</a><br></div><d=
iv>Sure, not an immediately intuitive syntax, but makes sense after a few s=
econds, and way better than the alternatives anyhow.<br><br></div></div></d=
iv></div>
</blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/77a0b930-c6dd-4fc0-8327-c38640d76392%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/77a0b930-c6dd-4fc0-8327-c38640d76392=
%40isocpp.org</a>.<br />
------=_Part_3168_199522804.1469456224236--
------=_Part_3167_275017417.1469456224236--
.
Author: szollosi.lorand@gmail.com
Date: Wed, 7 Sep 2016 11:46:03 -0700 (PDT)
Raw View
------=_Part_4_624953030.1473273963865
Content-Type: multipart/alternative;
boundary="----=_Part_5_1718330317.1473273963866"
------=_Part_5_1718330317.1473273963866
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi,
(still working on this...)
Let's revisit visitation. How would you feel about:
std::tuple<int, char, double> nums;
for (auto& v : nums)
{
v([](auto n) {
std::cout << n;
}
}
? That is, define std::tuple<..>::begin() and end() returning visiting=20
iterators (iterators that have operator() that calls the parameter with the=
=20
corresponding element). This doesn't require any syntax change (albeit=20
compiler support is still desirable to eliminate type switch / virtuals)=20
and we could tick this item on the list. As for the rest, I'm generalizing=
=20
it a bit..
Thanks,
-lorro
2016. j=C3=BAlius 25., h=C3=A9tf=C5=91 16:17:04 UTC+2 id=C5=91pontban szoll=
os...@gmail.com a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> Ok, so perhaps we can set aside tuple_for for this one. (I'd also like to=
=20
> see better tuple <-> params & init list interwork, but that deserves a=20
> separate, longer thread).
> Do you think there's anything to add to the *for* & *while* before we=20
> make a draft?
> Also - do you perhaps have any thoughts on why the previous draft on *for=
*=20
> didn't make it and how to improve so that this one does?
>
> Thanks,
> -lorro
>
> 2016. j=C3=BAlius 24., vas=C3=A1rnap 1:12:57 UTC+2 id=C5=91pontban D. B. =
a k=C3=B6vetkez=C5=91t=20
> =C3=ADrta:
>>
>> On Sun, Jul 24, 2016 at 12:00 AM, Nicol Bolas <jmck...@gmail.com> wrote:
>>>
>>> To be fair, it's not easy to write code that will be executed for each=
=20
>>> element in a tuple. It represents a hole in doing things with tuples.
>>>
>>> It's easy to build a tuple. It's easy to pass tuples around. It's easy=
=20
>>> to get a single element from a tuple. These basic uses of a tuple do no=
t=20
>>> require complex metaprogramming techniques.
>>>
>>> But to perform an act, even if it's just a single function call, on eac=
h=20
>>> element requires metaprogramming. Granted, performing an act for each=
=20
>>> member of a struct requires... well, it requires macros & metaprogrammi=
ng,=20
>>> so it's much worse. But with a tuple, it seems (from the perspective of=
a=20
>>> novice) to be such a simple thing.
>>>
>>> Hence my desire for tuple-to-pack transformations. That's a simple thin=
g=20
>>> that they can understand.
>>>
>>
>> Yeah, that sounds preferable, especially by using existing (if, at least=
=20
>> from what I've seen, a bit underused) syntax, rather than requiring anot=
her=20
>> new set, which would be redundant.
>>
>> Maybe I was thinking of something else when I implied it wasn't that=20
>> difficult... a quick scan shows it looks rather thorny.
>>
>> BUT! This looks promising if accurate (not tested it myself):=20
>> http://stackoverflow.com/a/37100197/2757035
>> Sure, not an immediately intuitive syntax, but makes sense after a few=
=20
>> seconds, and way better than the alternatives anyhow.
>>
>>
--=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/24c6acbf-aad3-4f5a-b9e0-1e49cc8c55c8%40isocpp.or=
g.
------=_Part_5_1718330317.1473273963866
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi,<br><br>(still working on this...)<br>Let's revisit=
visitation. How would you feel about:<br><br>std::tuple<int, char, doub=
le> nums;<br>for (auto& v : nums)<br>{<br>=C2=A0=C2=A0=C2=A0 v([](au=
to n) {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::cout << n;=
<br>=C2=A0=C2=A0=C2=A0 }<br>}<br><br>? That is, define std::tuple<..>=
::begin() and end() returning visiting iterators (iterators that have opera=
tor() that calls the parameter with the corresponding element). This doesn&=
#39;t require any syntax change (albeit compiler support is still desirable=
to eliminate type switch / virtuals) and we could tick this item on the li=
st. As for the rest, I'm generalizing it a bit..<br><br>Thanks,<br>-lor=
ro<br><br>2016. j=C3=BAlius 25., h=C3=A9tf=C5=91 16:17:04 UTC+2 id=C5=91pon=
tban szollos...@gmail.com a k=C3=B6vetkez=C5=91t =C3=ADrta:<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">Ok, so perhaps we can set asi=
de tuple_for for this one. (I'd also like to see better tuple <->=
params & init list interwork, but that deserves a separate, longer thr=
ead).<br>Do you think there's anything to add to the <i>for</i> & <=
i>while</i> before we make a draft?<br>Also - do you perhaps have any thoug=
hts on why the previous draft on <i>for</i> didn't make it and how to i=
mprove so that this one does?<br><br>Thanks,<br>-lorro<br><br>2016. j=C3=BA=
lius 24., vas=C3=A1rnap 1:12:57 UTC+2 id=C5=91pontban D. B. a k=C3=B6vetkez=
=C5=91t =C3=ADrta:<blockquote class=3D"gmail_quote" style=3D"margin:0;margi=
n-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
<div><div class=3D"gmail_quote">On Sun, Jul 24, 2016 at 12:00 AM, Nicol Bol=
as <span dir=3D"ltr"><<a rel=3D"nofollow">jmck...@gmail.com</a>></spa=
n> wrote:<blockquote style=3D"margin:0px 0px 0px 0.8ex;border-left:1px soli=
d rgb(204,204,204);padding-left:1ex" class=3D"gmail_quote"><div dir=3D"ltr"=
><div>To be fair, it's not easy to write code that will be executed for=
each element in a tuple. It represents a hole in doing things with tuples.=
<br><br>It's easy to build a tuple. It's easy to pass tuples around=
.. It's easy to get a single element from a tuple. These basic uses of a=
tuple do not require complex metaprogramming techniques.<br><br>But to per=
form an act, even if it's just a single function call, on each element =
requires metaprogramming. Granted, performing an act for each member of a s=
truct requires... well, it requires macros & metaprogramming, so it'=
;s much worse. But with a tuple, it seems (from the perspective of a novice=
) to be such a simple thing.<br><br>Hence my desire for tuple-to-pack trans=
formations. That's a simple thing that they can understand.<br></div></=
div></blockquote><div><br></div><div>Yeah, that sounds preferable, especial=
ly by using existing (if, at least from what I've seen, a bit underused=
) syntax, rather than requiring another new set, which would be redundant.<=
br><br></div><div>Maybe I was thinking of something else when I implied it =
wasn't that difficult... a=C2=A0 quick scan shows it looks rather thorn=
y.<br><br></div><div>BUT! This looks promising if accurate (not tested it m=
yself): <a href=3D"http://stackoverflow.com/a/37100197/2757035" rel=3D"nofo=
llow" target=3D"_blank" onmousedown=3D"this.href=3D'http://www.google.c=
om/url?q\x3dhttp%3A%2F%2Fstackoverflow.com%2Fa%2F37100197%2F2757035\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFe3ZZzNWldPoUcEg4GBWRmQBcwaA';return t=
rue;" onclick=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F=
%2Fstackoverflow.com%2Fa%2F37100197%2F2757035\x26sa\x3dD\x26sntz\x3d1\x26us=
g\x3dAFQjCNFe3ZZzNWldPoUcEg4GBWRmQBcwaA';return true;">http://stackover=
flow.com/a/<wbr>37100197/2757035</a><br></div><div>Sure, not an immediately=
intuitive syntax, but makes sense after a few seconds, and way better than=
the alternatives anyhow.<br><br></div></div></div></div>
</blockquote></div></blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/24c6acbf-aad3-4f5a-b9e0-1e49cc8c55c8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/24c6acbf-aad3-4f5a-b9e0-1e49cc8c55c8=
%40isocpp.org</a>.<br />
------=_Part_5_1718330317.1473273963866--
------=_Part_4_624953030.1473273963865--
.
Author: szollosi.lorand@gmail.com
Date: Sun, 9 Oct 2016 07:49:10 -0700 (PDT)
Raw View
------=_Part_284_313983728.1476024550709
Content-Type: multipart/alternative;
boundary="----=_Part_285_2086511315.1476024550710"
------=_Part_285_2086511315.1476024550710
Content-Type: text/plain; charset=UTF-8
Hi,
tl;dr: this is provided w/o additional language support:
void function(std::vector<int> v)
{
for (int j = 0; j < 2; ++j) break_label(abc) {
// Choose exactly one of these by uncommenting:
// int i; for_if_nodecl(i : v) { // C++98
// int i; for_if(i : v) { // C++11
for_if(auto&& i : v) { // C++11
std::cout << " " << i;
if (2 < i && i < 5) { break; }
}
else if ( _empty ) { std::cout << " empty"; }
else if (!_break && _broken) { std::cout << " last"; }
else if (!_break &&!_broken) { std::cout << " done"; }
else if ( _break ) {
std::cout << " (break at " << *_begin
<< ", broken: " << _broken << ") ";
if (*_begin > 3) {
std::cout << std::endl;
break_to(abc);
}
continue_from_break;
}
std::cout << std::endl;
}
}
I had some time to work on this; I've made a macro-based implementation.
/* Why macro? Of course, the expected result is a language feature in the
next standard; however, that could use some input from actual use cases.
The time it takes to roll out - not just for compilers, but to companies -
the build env. supporting the new standard might justify the idea of a
transition / backport package. Some of these macros are C++98, which might
bridge a 20-year gap. Also, a macro can be undefined at the end of the code
parts using it :). */
Interestingly, newer gcc versions optimize this quite well. Expect about 2x
- 3x the number of instructions than a plain old loop. Naturally, this is
currently not for tight inner loops, that'd need language and optimizer
support.
Some thoughts on implementing:
- for_if means literally `if`. Thus there are `else` / `else if`
branches. Note that the loop might reenter multiple times, therefore the
else branches are not mutually exclusive, nor can you expect that execution
directly continues from `else` to next instructions. The `else` / `else if`
branches are *part of* the loop. The keywords `continue` and `break`
work as expected *in the body* of the loop.
- It is possible to continue the same loop after break. You can either
reenter (same loop var) or continue_from_break (next loop var). If you
continue (either way), you'll get the `else` branch at the end of the loop.
Particularly, if you break at the last element, then continue_from_break,
you'll get to the `else` branch again. If this is not desirable, test for
`!_broken` instead of `!break` for done event. Thus you get the following
seven events: (with variables available in `else` only)
- entering the body of the loop
- range was empty: else if (!_empty)
- first break: else if (_break && !_broken), _begin .. _end is the
remaining range including the current element
- subsequent break: else if (_break && !_broken), _begin .. _end is
the remaining range including the current element
- loop finished without break: else if (!_break && !_broken)
- loop finished after reenter / continue_from_break: else if (!_break
&& _broken)
- It makes more sense to me to have a view on the entire range in break
handler, based on iterators. That allows manipulating the range before exit
/ reentry. Let me know if you have strong preference for loop variable
there.
- Another interesting feature that's not implemented here is special
handling of the first element (prelude). Ideally that'd be unrolled by the
compiler, an `if (_first)` is too bad performance-wise (and manual loop
body duplication is a no-go).
- After considering multiple solutions, I decided to say `break` and
`continue` are UB from the `else` branch. I feel particularly bad about
`for (v : vs) for_if (i : v) break; else break;`, where the two `break`
statements would return to *different* places. That's simply unnatural
and has a great potential for ending up in errors. Instead, we have now
label-based `break_to()` and `continue_to()`, mimicking the proposal on
`break label;` and `continue label;`.
- In for_if, only auto, auto&, auto&& declarations and predeclared
variables are supported. So far I see this rather an advantage than
limitation, but let me know if you feel differently.
- It can be used as a single statement, but note that `else` binds to it.
- It's not coroutine-compatible, sorry. (You can't goto or `switch`-jump
into for_if *or* its `else`.)
- Several things could make it easier; incl. `constexpr?:` expressions *and
*statements, `if()` interpreting declarations that can't cast to bool /
integer as true, macros allowing `:` (and perhaps `;` - or anything else)
as separator; perhaps even c++-like parentheses. On the other thread I
brought up the idea of `for_impl (auto&& i : v) { ... }` meaning like
`for_impl( [&, take_return, take_break, take_continue](auto&& i) { ...
})(v);`, i.e., to make `for` an operator that transforms an element-wise
lambda to one that takes a range. That's one way to go and, when done, it'd
simplify optional visitation, make index-based loops trivial; but that
needs heavy language support.
If anyone dares to use it, or experiment with it, I'd be more than glad for
any feedback, which is essential for the further steps in standardization
of any of these.
Thanks,
-lorro
--
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/b8e3fc52-e79f-4464-ae72-5c4ea48ea7d0%40isocpp.org.
------=_Part_285_2086511315.1476024550710
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi,<br><br>tl;dr: this is provided w/o additional language=
support:<br><div class=3D"prettyprint" style=3D"background-color: rgb(250,=
250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-w=
idth: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">function</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">vector</span><span style=3D"color: #=
080;" class=3D"styled-by-prettify"><int></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> v</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">for</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> j </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> j </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">2</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">++</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">j</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> break_label</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">abc</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 sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #800;" class=3D"styled-by-prettify">// Choose exactly one of these b=
y uncommenting:</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">/=
/ =C2=A0 =C2=A0 =C2=A0int i; for_if_nodecl(i : v) =C2=A0{ // C++98</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">// =C2=A0 =C2=A0 =C2=A0in=
t i; for_if(i : v) =C2=A0 =C2=A0 =C2=A0 =C2=A0 { // C++11</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 for_if</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&&</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> i </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> v</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 </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: #800;" =
class=3D"styled-by-prettify">// C++11</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">cout </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify"><<</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #080;" 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"> i</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">if</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: #066;" =
class=3D"styled-by-prettify">2</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-prett=
ify"> i </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&a=
mp;&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> i=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #066;" class=3D"styled-by-prettify">5</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">break</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 sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">else</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">if</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> _empty </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"color: =
#660;" class=3D"styled-by-prettify"><<</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" clas=
s=3D"styled-by-prettify">" empty"</span><span style=3D"color: #66=
0;" 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-pret=
tify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">else</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">if</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(!=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">_break </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&&</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> _broken</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">cout </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify"><<</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettif=
y">" last"</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> =C2=A0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">}<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">else</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">if</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(!</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">_break </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&&!</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">_broken</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><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">cout </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #080;" class=3D"styled-by-prettify">" done&q=
uot;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">els=
e</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> _break </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=
"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 std</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">cout </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><<</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"sty=
led-by-prettify">" (break at "</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"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>_begin<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy"><<</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">",=
broken: "</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> _brok=
en </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: #080;" class=3D"styled-by-prettify">") "</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">if</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(*=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">_begin </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">></span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">3</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"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 std<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">cout </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify"><<</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">endl</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 break_to</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">abc<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue_from_break<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 std</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">cout </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify"><<</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">endl</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br></span></div></code></div><br=
>I had some time to work on this; I've made a macro-based implementatio=
n.<br>/* Why macro? Of course, the expected result is a language feature in=
the next standard; however, that could use some input from actual use case=
s. The time it takes to roll out - not just for compilers, but to companies=
- the build env. supporting the new standard might justify the idea of a t=
ransition / backport package. Some of these macros are C++98, which might b=
ridge a 20-year gap. Also, a macro can be undefined at the end of the code =
parts using it :). */<br>Interestingly, newer gcc versions optimize this qu=
ite well. Expect about 2x - 3x the number of instructions than a plain old =
loop. Naturally, this is currently not for tight inner loops, that'd ne=
ed language and optimizer support.<br>Some thoughts on implementing:<br><ul=
><li>for_if means literally `if`. Thus there are `else` / `else if` branche=
s. Note that the loop might reenter multiple times, therefore the else bran=
ches are not mutually exclusive, nor can you expect that execution directly=
continues from `else` to next instructions. The `else` / `else if` branche=
s are <i>part of</i> the loop. The keywords `continue` and `break` work as =
expected <i>in the body</i> of the loop.<br></li><li>It is possible to cont=
inue the same loop after break. You can either reenter (same loop var) or c=
ontinue_from_break (next loop var). If you continue (either way), you'l=
l get the `else` branch at the end of the loop. Particularly, if you break =
at the last element, then continue_from_break, you'll get to the `else`=
branch again. If this is not desirable, test for `!_broken` instead of `!b=
reak` for done event. Thus you get the following seven events: (with variab=
les available in `else` only)<br></li><ul><li>entering the body of the loop=
</li><li>range was empty: else if (!_empty)</li><li>first break: else if (_=
break && !_broken), _begin .. _end is the remaining range including=
the current element<br></li><li>subsequent break: else if (_break &&am=
p; !_broken), _begin .. _end is the remaining range including the current e=
lement</li><li>loop finished without break: else if (!_break && !_b=
roken)</li><li>loop finished after reenter / continue_from_break: else if (=
!_break && _broken)</li></ul><li>It makes more sense to me to have =
a view on the entire range in break handler, based on iterators. That allow=
s manipulating the range before exit / reentry. Let me know if you have str=
ong preference for loop variable there.</li><li>Another interesting feature=
that's not implemented here is special handling of the first element (=
prelude). Ideally that'd be unrolled by the compiler, an `if (_first)` =
is too bad performance-wise (and manual loop body duplication is a no-go).<=
br></li><li>After considering multiple solutions, I decided to say `break` =
and `continue` are UB from the `else` branch. I feel particularly bad about=
`for (v : vs) for_if (i : v) break; else break;`, where the two `break` st=
atements would return to <i>different</i> places. That's simply unnatur=
al and has a great potential for ending up in errors. Instead, we have now =
label-based `break_to()` and `continue_to()`, mimicking the proposal on `br=
eak label;` and `continue label;`.<br></li><li>In for_if, only auto, auto&a=
mp;, auto&& declarations and predeclared variables are supported. S=
o far I see this rather an advantage than limitation, but let me know if yo=
u feel differently.</li><li>It can be used as a single statement, but note =
that `else` binds to it.<br></li><li>It's not coroutine-compatible, sor=
ry. (You can't goto or `switch`-jump into for_if <i>or</i> its `else`.)=
</li><li>Several things could make it easier; incl. `constexpr?:` expressio=
ns <i>and </i>statements, `if()` interpreting declarations that can't c=
ast to bool / integer as true, macros allowing `:` (and perhaps `;` - or an=
ything else) as separator; perhaps even c++-like parentheses. On the other =
thread I brought up the idea of `for_impl (auto&& i : v) { ... }` m=
eaning like `for_impl( [&, take_return, take_break, take_continue](auto=
&& i) { ... })(v);`, i.e., to make `for` an operator that transform=
s an element-wise lambda to one that takes a range. That's one way to g=
o and, when done, it'd simplify optional visitation, make index-based l=
oops trivial; but that needs heavy language support.<br></li></ul>If anyone=
dares to use it, or experiment with it, I'd be more than glad for any =
feedback, which is essential for the further steps in standardization of an=
y of these.<br><br>Thanks,<br>-lorro<br><div><div class=3D"gmail_quote"><di=
v><br></div></div></div><blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div d=
ir=3D"ltr"><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"><blockq=
uote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:=
1px #ccc solid;padding-left:1ex">
</blockquote></div></blockquote></div></blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b8e3fc52-e79f-4464-ae72-5c4ea48ea7d0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b8e3fc52-e79f-4464-ae72-5c4ea48ea7d0=
%40isocpp.org</a>.<br />
------=_Part_285_2086511315.1476024550710--
------=_Part_284_313983728.1476024550709
Content-Type: text/x-c++src; charset=US-ASCII; name=for.cpp
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=for.cpp
X-Attachment-Id: 11b66899-d8b9-4bb8-8dc9-8a4e8172eb26
Content-ID: <11b66899-d8b9-4bb8-8dc9-8a4e8172eb26>
#include <vector>
#include <iostream>
#define DECL_GUARD for(bool _decl = true; _decl; _decl = false)
#define DECL(X) for(X; _decl; _decl = false)
#define reenter_m if (true) { _s = !(_begin != _end) - 1; _broken = true; _break = false; continue; } else []{}()
#define continue_from_break_m if (true) { ++_begin; reenter_m; } else []{}()
#define reenter if (true) { _s = -1; _broken = true; _break = false; continue; } else []{}()
#define continue_from_break if (true) { ++_begin; reenter; } else []{}()
#define \
for_if_m(decl, r) \
DECL_GUARD \
DECL(auto&& _range = r ) \
DECL(auto _begin = begin(_range) ) \
DECL(auto _end = end(_range) ) \
DECL(bool _break = false ) \
DECL(bool _broken = false ) \
DECL(bool _empty = !(_begin != _end)) \
DECL(char _s = _empty ) \
for(; _s != 2; ++_s) \
if (!_s) switch (true) \
for (; !_break && (_begin != _end); \
!_break && (++_begin, true)) default: \
for (decl = (_break = true, *_begin); \
_break; _break = false)
enum dontcare_t { dontcare }; // C++98
// enum { dontcare }; // C++11
struct DontCare
{
template<typename T>
operator T&() { return *(T*)0; }
};
// C++98:
//template<typename T>
//DontCare operator<<(dontcare_t, T)
template<typename T>
DontCare operator<<(decltype(dontcare), T)
{
return {};
}
// C++98:
//template<typename T>
//DontCare operator>>(T, dontcare_t)
template<typename T>
DontCare operator>>(T, decltype(dontcare))
{
return {};
}
#define for_if_nodecl(X) for_if_m((true ? X >> dontcare), (false ? dontcare << X))
// C++11 from here
template<typename It>
struct observe_range
{
It& _begin;
It& _end;
char& _s;
bool& _break;
bool& _empty;
};
template<typename It>
observe_range<It> make_observe_range(It& _begin, It& _end, char& _s, bool& _break, bool& _empty)
{
return { _begin, _end, _s, _break, _empty };
}
template<typename It>
struct observed_it
{
static char s_sdontcare;
static bool s_bdontcare;
It& _it;
char& _s;
bool& _break;
bool operator!=(const observed_it& rhs) const
{
return _s && (_s = !_break && (_it != rhs._it), true);
}
void operator++() {}
auto operator*() -> decltype( *_it ) { return *_it; }
auto operator*() const-> decltype( *_it ) { return *_it; }
observed_it()
: _s(s_sdontcare)
, _break(s_bdontcare) {}
observed_it(It& it)
: _it(it)
, _s(s_sdontcare)
, _break(s_bdontcare) {}
observed_it(It& it, char& sref, bool& breakref)
: _it(it)
, _s(sref)
, _break(breakref) {}
};
template<typename It>
char observed_it<It>::s_sdontcare = 0;
template<typename It>
bool observed_it<It>::s_bdontcare = false;
template<typename R>
struct observed_range
{
typedef decltype(begin(std::declval<R>())) It;
R r;
char& _s;
bool& _break;
It& _begin;
It& _end;
observed_it<It> begin() { return { _begin, _s, _break }; }
observed_it<It> begin() const { return { _begin, _s, _break }; }
observed_it<It> end() { return { _end }; }
observed_it<It> end() const { return { _end }; }
};
template<typename R>
observed_range<R> operator|(R&& r, observe_range<decltype(begin(r))> obs)
{
observed_range<R> ret = { std::forward<R>(r), obs._s, obs._break, obs._begin, obs._end };
obs._begin = begin(ret.r);
obs._end = end(ret.r);
obs._empty = !(ret._begin != ret._end);
obs._s = 1;
return ret;
}
#define \
for_if_decl(X) \
DECL_GUARD \
DECL(decltype(begin(v)) _begin ) \
DECL(decltype(begin(v)) _end ) \
DECL(char _s = 1 ) \
DECL(bool _break = false) \
DECL(bool _broken = false) \
DECL(bool _empty = false) \
for (X | make_observe_range( _begin, _end, _s, _break, _empty )) \
if (_s == 1) \
for (_break = true; \
_break; \
_break = false, ++_begin) \
#define FOR_IF_MATCH_auto , for_if_decl, auto
#define CAT_(X, Y) X ## Y
#define CAT(X, Y) CAT_(X, Y)
#define for_if__(_1, F, P, ...) F(P)
#define for_if_(...) for_if__(__VA_ARGS__)
#define for_if(X) for_if_(CAT(FOR_IF_MATCH_, X), for_if_nodecl, X, 0)
#define break_label(l) if (false) break_ ## l: break; else
#define continue_label(l) if (false) continue_ ## l: continue; else
#define break_continue_label(l) break_label(l) continue_label(l)
#define break_to(l) goto break_ ## l
#define continue_to(l) goto continue_ ## l
void function(std::vector<int> v)
{
auto diag = [&](int j) {
std::cout << "vector: ";
for (auto i : v) {
std::cout << i << " ";
}
std::cout << "run: " << j << std::endl;
};
for (int j = 0; j < 2; ++j) break_label(abc) {
diag(j);
// Choose exactly one of these by uncommenting:
// int i; for_if_m(i, v) { // like macro, predeclared loop variable, C++98
// for_if_m(auto&& i, v) { // like macro, loop variable declaration, C++98
// int i; for_if_nodecl(i : v) { // like range for, predeclared loop variable, C++98
// for_if_decl(auto&& i : v) { // like range for, loop variable declaration, C++11
// int i; for_if(i : v) { // like range for, predeclared/auto loop variable, C++11
for_if(auto&& i : v) { // -"-
std::cout << " " << i;
if (2 < i && i < 5) { break; }
}
else if ( _empty ) { std::cout << " empty"; }
else if (!_break && _broken) { std::cout << " last"; }
else if (!_break &&!_broken) { std::cout << " done"; }
else if ( _break ) {
std::cout << " (break at " << *_begin << ", broken: " << _broken << ") ";
if (*_begin > 3) {
std::cout << std::endl;
break_to(abc);
}
continue_from_break;
}
std::cout << std::endl;
}
}
int main()
{
std::vector<int> v1{1, 2, 3, 4, 5, 6};
std::vector<int> v2{1, 2, 3};
std::vector<int> v3{1, 2};
std::vector<int> v4;
function(v1); function(v2); function(v3); function(v4);
}
------=_Part_284_313983728.1476024550709--
.