Topic: Enhancements for basic control structures
Author: Markus Grech <markus.grech@gmail.com>
Date: Fri, 29 Aug 2014 09:45:44 -0700 (PDT)
Raw View
------=_Part_396_1628617387.1409330744325
Content-Type: text/plain; charset=UTF-8
Hi, I would like to gather some initial feedback about my ideas before
writing proposals.
My first idea is to make negated conditions easier to write and read. The
extra parenthesis always looked odd to me and negating a condition while
editing is like a little pain.
I would like to propose that the ! can be put before the parenthesis for
the condition in the if and while constructs.
if!(cond)
while!(cond)
This would be a built-in construct in the language.
My second idea is unify the do-notation in loops by allowing it to be
applied to any loop. The do-while loop is no longer a special looping
construct, it's a regular while loop with a do-block and an empty statement
as its body.
do stuff1;
while(cond)
stuff2;
The semantics of this would be equivalent to:
for(;;)
{
stuff1;
if(!(cond))
break;
stuff2;
}
Similarly, this construct is allowed for for- and foreach-loops.
An example usage of this would be to write a command prompt:
do std::cout << "> ";
for(std::string line; std::getline(std::cin, line);)
process(line);
It could also be useful to add debug output to an existing read-loop.
The variable defined in the for-loop is not accessible in the do-block, but
initialized before anything else.
My third and last idea is to allow loop to have an optional else-block that
would be executed if the condition was never true, that is, the body of the
loop has been executed 0 times. This can be especially useful to handle
empty containers for example:
for(auto& elem : container)
std::cout << elem << '\n';
else
std::cout << "no elements\n";
What do you think? If I were to propose these ideas, should I write a
single proposal or three seperate ones?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_396_1628617387.1409330744325
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi, I would like to gather some initial feedback about my =
ideas before writing proposals.<br><br>My first idea is to make negated con=
ditions easier to write and read. The extra parenthesis always looked odd t=
o me and negating a condition while editing is like a little pain.<br>I wou=
ld like to propose that the ! can be put before the parenthesis for the con=
dition in the if and while constructs.<br><div class=3D"prettyprint" 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 clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;=
" class=3D"styled-by-prettify">if</span><span style=3D"color: #660;" class=
=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: #000;" class=3D"styled-by-prettify"=
><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">while=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">!(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">cond</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span></div></code></div>Thi=
s would be a built-in construct in the language.<br><br>My second idea is u=
nify the do-notation in loops by allowing it to be applied to any loop. The=
do-while loop is no longer a special looping construct, it's a regular whi=
le loop with a do-block and an empty statement as its body.<br><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
style=3D"color: #008;" class=3D"styled-by-prettify">do</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> stuff1</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">while</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">cond</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br> stuff2</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span></div></code></div>The semantics of this would be equivalen=
t to:<br><div class=3D"prettyprint" 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"su=
bprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">for=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(;;)</span=
><span style=3D"color: #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> stuff1</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br><br> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">(!(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">cond</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">))</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">break</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br><br> stuff2</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=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></span></div></code></div>Similarly,=
this construct is allowed for for- and foreach-loops.<br><br>An example us=
age of this would be to write a command prompt:<br><div class=3D"prettyprin=
t" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 18=
7, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><c=
ode class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">do</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">cout </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify"><<</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #080;" 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></span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">for</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">string</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> line</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">getl=
ine</span><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=
"color: #000;" class=3D"styled-by-prettify">cin</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> line</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">);)</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br> process</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">line</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span></div></code></div>It could also be useful to add debu=
g output to an existing read-loop.<br>The variable defined in the for-loop =
is not accessible in the do-block, but initialized before anything else.<br=
><br>My third and last idea is to allow loop to have an optional else-block=
that would be executed if the condition was never true, that is, the body =
of the loop has been executed 0 times. This can be especially useful to han=
dle empty containers for example:<br><div class=3D"prettyprint" style=3D"ba=
ckground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); borde=
r-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"p=
rettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">for</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">auto</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> e=
lem </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> container</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> std</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">cout </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><<</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> elem </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080=
;" class=3D"styled-by-prettify">'\n'</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">else</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br> std</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">cout </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">"no elem=
ents\n"</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><=
/div></code></div><br>What do you think? If I were to propose these ideas, =
should I write a single proposal or three seperate ones?<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_396_1628617387.1409330744325--
.
Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Fri, 29 Aug 2014 19:20:14 +0200
Raw View
On Fri, Aug 29, 2014 at 09:45:44AM -0700, Markus Grech wrote:
> Hi, I would like to gather some initial feedback about my ideas before
> writing proposals.
>
> My first idea is to make negated conditions easier to write and read. The
> extra parenthesis always looked odd to me and negating a condition while
> editing is like a little pain.
> I would like to propose that the ! can be put before the parenthesis for
> the condition in the if and while constructs.
> if!(cond)
> while!(cond)
> This would be a built-in construct in the language.
I assume that it would be permitted to declare variables in the parentheses?
if not (int i = fun())
{ /* Do something with i */ }
> What do you think? If I were to propose these ideas, should I write a
> single proposal or three seperate ones?
The three are unrelated - write three proposals.
I would like the first one.
All of them will probably be rejected, as it have been said that new control
structures are rather unwished for.
/MF
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Markus Grech <markus.grech@gmail.com>
Date: Fri, 29 Aug 2014 10:28:26 -0700 (PDT)
Raw View
------=_Part_409_2001396427.1409333306065
Content-Type: text/plain; charset=UTF-8
On Friday, August 29, 2014 7:20:18 PM UTC+2, Magnus Fromreide wrote:
>
> On Fri, Aug 29, 2014 at 09:45:44AM -0700, Markus Grech wrote:
> > Hi, I would like to gather some initial feedback about my ideas before
> > writing proposals.
> >
> > My first idea is to make negated conditions easier to write and read.
> The
> > extra parenthesis always looked odd to me and negating a condition while
> > editing is like a little pain.
> > I would like to propose that the ! can be put before the parenthesis for
> > the condition in the if and while constructs.
> > if!(cond)
> > while!(cond)
> > This would be a built-in construct in the language.
>
> I assume that it would be permitted to declare variables in the
> parentheses?
>
> if not (int i = fun())
> { /* Do something with i */ }
>
Yes, absolutely. I didn't actually think of those cases, although they have
occured to me as well, which is another good reason for introducing that
syntax.
Thanks for your feedback.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_409_2001396427.1409333306065
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Friday, August 29, 2014 7:20:18 PM UTC+2, Magnus Fromre=
ide wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Fri, Aug 29, 2014=
at 09:45:44AM -0700, Markus Grech wrote:
<br>> Hi, I would like to gather some initial feedback about my ideas be=
fore=20
<br>> writing proposals.
<br>>=20
<br>> My first idea is to make negated conditions easier to write and re=
ad. The=20
<br>> extra parenthesis always looked odd to me and negating a condition=
while=20
<br>> editing is like a little pain.
<br>> I would like to propose that the ! can be put before the parenthes=
is for=20
<br>> the condition in the if and while constructs.
<br>> if!(cond)
<br>> while!(cond)
<br>> This would be a built-in construct in the language.
<br>
<br>I assume that it would be permitted to declare variables in the parenth=
eses?
<br>
<br>if not (int i =3D fun())
<br> { /* Do something with i */ }
<br></blockquote><div>Yes, absolutely. I didn't actually think of those cas=
es, although they have occured to me as well, which is another good reason =
for introducing that syntax.<br>Thanks for your feedback.<br> </div></=
div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_409_2001396427.1409333306065--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Fri, 29 Aug 2014 14:15:59 -0700
Raw View
--089e01634bf0deb0d80501cb2881
Content-Type: text/plain; charset=UTF-8
On Fri, Aug 29, 2014 at 9:45 AM, Markus Grech <markus.grech@gmail.com>
wrote:
> Hi, I would like to gather some initial feedback about my ideas before
> writing proposals.
>
> My first idea is to make negated conditions easier to write and read. The
> extra parenthesis always looked odd to me and negating a condition while
> editing is like a little pain.
> I would like to propose that the ! can be put before the parenthesis for
> the condition in the if and while constructs.
> if!(cond)
> while!(cond)
> This would be a built-in construct in the language.
>
> My second idea is unify the do-notation in loops by allowing it to be
> applied to any loop. The do-while loop is no longer a special looping
> construct, it's a regular while loop with a do-block and an empty statement
> as its body.
> do stuff1;
> while(cond)
> stuff2;
> The semantics of this would be equivalent to:
> for(;;)
> {
> stuff1;
>
> if(!(cond))
> break;
>
> stuff2;
> }
> Similarly, this construct is allowed for for- and foreach-loops.
>
> An example usage of this would be to write a command prompt:
> do std::cout << "> ";
> for(std::string line; std::getline(std::cin, line);)
> process(line);
> It could also be useful to add debug output to an existing read-loop.
> The variable defined in the for-loop is not accessible in the do-block,
> but initialized before anything else.
>
> My third and last idea is to allow loop to have an optional else-block
> that would be executed if the condition was never true, that is, the body
> of the loop has been executed 0 times. This can be especially useful to
> handle empty containers for example:
> for(auto& elem : container)
> std::cout << elem << '\n';
> else
> std::cout << "no elements\n";
>
>
What would this mean:
if (x)
for (blah : y)
thing;
else
thing;
Also, python has a for-else construct that means something completely
different (the else block is reached if the loop terminates normally -- not
by 'break'). I think this is the wrong syntax, even if the functionality is
useful (which I'm unconvinced by, FWIW).
> What do you think? If I were to propose these ideas, should I write a
> single proposal or three seperate ones?
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--089e01634bf0deb0d80501cb2881
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 F=
ri, Aug 29, 2014 at 9:45 AM, Markus Grech <span dir=3D"ltr"><<a href=3D"=
mailto:markus.grech@gmail.com" target=3D"_blank">markus.grech@gmail.com</a>=
></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr">Hi, I would like to gather =
some initial feedback about my ideas before writing proposals.<br><br>My fi=
rst idea is to make negated conditions easier to write and read. The extra =
parenthesis always looked odd to me and negating a condition while editing =
is like a little pain.<br>
I would like to propose that the ! can be put before the parenthesis for th=
e condition in the if and while constructs.<br><div style=3D"background-col=
or:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border=
-width:1px;word-wrap:break-word">
<code><div><span style=3D"color:#008">if</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"><br></span><span style=3D"color:#008">whil=
e</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"><br>
</span></div></code></div>This would be a built-in construct in the languag=
e.<br><br>My second idea is unify the do-notation in loops by allowing it t=
o be applied to any loop. The do-while loop is no longer a special looping =
construct, it's a regular while loop with a do-block and an empty state=
ment as its body.<br>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">do</span><span style=3D"color:#000"> stuff1</span><=
span style=3D"color:#660">;</span><span style=3D"color:#000"><br>
</span><span style=3D"color:#008">while</span><span style=3D"color:#660">(<=
/span><span style=3D"color:#000">cond</span><span style=3D"color:#660">)</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 stuff2</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br>
</span></div></code></div>The semantics of this would be equivalent to:<br>=
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">for</span><span style=3D"color:#660">(;;)</span><sp=
an style=3D"color:#000"><br>
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 stuff1</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">if<=
/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"><br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">break</span><=
span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br>=C2=A0=
=C2=A0 stuff2</span><span style=3D"color:#660">;</span><span style=3D"colo=
r:#000"><br></span><span style=3D"color:#660">}</span><span style=3D"color:=
#000"><br>
</span></div></code></div>Similarly, this construct is allowed for for- and=
foreach-loops.<br><br>An example usage of this would be to write a command=
prompt:<br><div style=3D"background-color:rgb(250,250,250);border-color:rg=
b(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word">
<code><div><span style=3D"color:#008">do</span><span style=3D"color:#000"> =
std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">co=
ut </span><span style=3D"color:#660"><<</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#080">"> "</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br>
</span><span style=3D"color:#008">for</span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#000">std</span><span style=3D"color:#660">::</spa=
n><span style=3D"color:#008">string</span><span style=3D"color:#000"> line<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"> std</s=
pan><span style=3D"color:#660">::</span><span style=3D"color:#000">getline<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#000">std</sp=
an><span style=3D"color:#660">::</span><span style=3D"color:#000">cin</span=
><span style=3D"color:#660">,</span><span style=3D"color:#000"> line</span>=
<span style=3D"color:#660">);)</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 process</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">line</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"><br></span></div></code></div>It could also be useful to ad=
d debug output to an existing read-loop.<br>
The variable defined in the for-loop is not accessible in the do-block, but=
initialized before anything else.<br><br>My third and last idea is to allo=
w loop to have an optional else-block that would be executed if the conditi=
on was never true, that is, the body of the loop has been executed 0 times.=
This can be especially useful to handle empty containers for example:<br>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">for</span><span style=3D"color:#660">(</span><span =
style=3D"color:#008">auto</span><span style=3D"color:#660">&</span><spa=
n style=3D"color:#000"> elem </span><span style=3D"color:#660">:</span><spa=
n style=3D"color:#000"> container</span><span style=3D"color:#660">)</span>=
<span style=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span><span style=3D"=
color:#000">cout </span><span style=3D"color:#660"><<</span><span sty=
le=3D"color:#000"> elem </span><span style=3D"color:#660"><<</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#080">'\n'</s=
pan><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>
</span><span style=3D"color:#008">else</span><span style=3D"color:#000"><br=
>=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span><span style=3D=
"color:#000">cout </span><span style=3D"color:#660"><<</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#080">"no elements\n&q=
uot;</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><b=
r>
</span></div></code></div><br></div></blockquote><div><br></div><div>What w=
ould this mean:</div><div><br></div><div>=C2=A0 if (x)</div><div>=C2=A0 =C2=
=A0 for (blah : y)</div><div>=C2=A0 =C2=A0 =C2=A0 thing;</div><div>=C2=A0 =
=C2=A0else</div><div>=C2=A0 =C2=A0 thing;</div>
<div><br></div><div>Also, python has a for-else construct that means someth=
ing completely different (the else block is reached if the loop terminates =
normally -- not by 'break'). I think this is the wrong syntax, even=
if the functionality is useful (which I'm unconvinced by, FWIW).</div>
<div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">What do yo=
u think? If I were to propose these ideas, should I write a single proposal=
or three seperate ones?<span class=3D"HOEnZb"><font color=3D"#888888"><br>
</font></span></div><span class=3D"HOEnZb"><font color=3D"#888888">
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--089e01634bf0deb0d80501cb2881--
.
Author: Markus Grech <markus.grech@gmail.com>
Date: Sat, 30 Aug 2014 03:10:35 -0700 (PDT)
Raw View
------=_Part_99_431233413.1409393435523
Content-Type: text/plain; charset=UTF-8
On Friday, August 29, 2014 11:16:00 PM UTC+2, Richard Smith wrote:
> What would this mean:
>
> if (x)
> for (blah : y)
> thing;
> else
> thing;
>
Ugh, the dangling else problem again. Guess I'll have to use a different
syntax then. How about for else/while else?
> Also, python has a for-else construct that means something completely
> different (the else block is reached if the loop terminates normally -- not
> by 'break'). I think this is the wrong syntax, even if the functionality is
> useful (which I'm unconvinced by, FWIW).
>
I fail to see the usefulness in pythons semantics, but I will do more
investigation. Thanks for the hint.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_99_431233413.1409393435523
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Friday, August 29, 2014 11:16:00 PM UTC+2, Richard Smit=
h wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><=
div><div class=3D"gmail_quote"><div>What would this mean:</div><div><br></d=
iv><div> if (x)</div><div> for (blah : y)</div><div>&nbs=
p; thing;</div><div> else</div><div> =
thing;</div></div></div></div></blockquote><div>Ugh, the dangling else pro=
blem again. Guess I'll have to use a different syntax then. How about for e=
lse/while else? <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 dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><d=
iv>Also, python has a for-else construct that means something completely di=
fferent (the else block is reached if the loop terminates normally -- not b=
y 'break'). I think this is the wrong syntax, even if the functionality is =
useful (which I'm unconvinced by, FWIW).</div></div></div></div></blockquot=
e><div>I fail to see the usefulness in pythons semantics, but I will do mor=
e investigation. Thanks for the hint.<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_99_431233413.1409393435523--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Sat, 30 Aug 2014 14:54:25 -0700
Raw View
--089e0163509428965e0501dfd004
Content-Type: text/plain; charset=UTF-8
On Sat, Aug 30, 2014 at 3:10 AM, Markus Grech <markus.grech@gmail.com>
wrote:
> On Friday, August 29, 2014 11:16:00 PM UTC+2, Richard Smith wrote:
>
>> What would this mean:
>>
>> if (x)
>> for (blah : y)
>> thing;
>> else
>> thing;
>>
> Ugh, the dangling else problem again. Guess I'll have to use a different
> syntax then. How about for else/while else?
>
>
>> Also, python has a for-else construct that means something completely
>> different (the else block is reached if the loop terminates normally -- not
>> by 'break'). I think this is the wrong syntax, even if the functionality is
>> useful (which I'm unconvinced by, FWIW).
>>
> I fail to see the usefulness in pythons semantics, but I will do more
> investigation. Thanks for the hint.
>
Here's a fairly typical usage pattern:
for (auto &elem : list) {
if (its_the_one_that_i_want) {
do_stuff_to_it();
break;
}
} else {
add_a_new_one(list);
}
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--089e0163509428965e0501dfd004
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=
at, Aug 30, 2014 at 3:10 AM, Markus Grech <span dir=3D"ltr"><<a href=3D"=
mailto:markus.grech@gmail.com" target=3D"_blank">markus.grech@gmail.com</a>=
></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D"">On Friday, =
August 29, 2014 11:16:00 PM UTC+2, Richard Smith wrote:<br><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc =
solid;padding-left:1ex">
<div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>What would this mean:=
</div><div><br></div><div>=C2=A0 if (x)</div><div>=C2=A0 =C2=A0 for (blah :=
y)</div><div>=C2=A0 =C2=A0 =C2=A0 thing;</div><div>=C2=A0 =C2=A0else</div>=
<div>=C2=A0 =C2=A0 thing;</div></div></div></div></blockquote>
</div><div>Ugh, the dangling else problem again. Guess I'll have to use=
a different syntax then. How about for else/while else? <br></div><div cla=
ss=3D""><div>=C2=A0</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"><div><div class=3D"gmail_quote"><div></div><div>Also, pyth=
on has a for-else construct that means something completely different (the =
else block is reached if the loop terminates normally -- not by 'break&=
#39;). I think this is the wrong syntax, even if the functionality is usefu=
l (which I'm unconvinced by, FWIW).</div>
</div></div></div></blockquote></div><div>I fail to see the usefulness in p=
ythons semantics, but I will do more investigation. Thanks for the hint.</d=
iv></div></blockquote><div><br></div><div>Here's a fairly typical usage=
pattern:</div>
<div><br></div><div>for (auto &elem : list) {</div><div>=C2=A0 if (its_=
the_one_that_i_want) {</div><div>=C2=A0 =C2=A0 do_stuff_to_it();</div><div>=
=C2=A0 =C2=A0 break;=C2=A0</div><div>=C2=A0 }</div><div>} else {</div><div>=
=C2=A0 add_a_new_one(list);</div><div>
}</div></div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--089e0163509428965e0501dfd004--
.
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Sun, 31 Aug 2014 01:33:08 +0200
Raw View
--001a11c366983acf4c0501e1312a
Content-Type: text/plain; charset=UTF-8
On Sat, Aug 30, 2014 at 11:54 PM, Richard Smith <richard@metafoo.co.uk>
wrote:
> On Sat, Aug 30, 2014 at 3:10 AM, Markus Grech <markus.grech@gmail.com>
> wrote:
>
>> On Friday, August 29, 2014 11:16:00 PM UTC+2, Richard Smith wrote:
>>
>>> What would this mean:
>>>
>>> if (x)
>>> for (blah : y)
>>> thing;
>>> else
>>> thing;
>>>
>> Ugh, the dangling else problem again. Guess I'll have to use a different
>> syntax then. How about for else/while else?
>>
>>
>>> Also, python has a for-else construct that means something completely
>>> different (the else block is reached if the loop terminates normally -- not
>>> by 'break'). I think this is the wrong syntax, even if the functionality is
>>> useful (which I'm unconvinced by, FWIW).
>>>
>> I fail to see the usefulness in pythons semantics, but I will do more
>> investigation. Thanks for the hint.
>>
>
> Here's a fairly typical usage pattern:
>
> for (auto &elem : list) {
> if (its_the_one_that_i_want) {
> do_stuff_to_it();
> break;
> }
> } else {
> add_a_new_one(list);
>
}
>
It can be done in one of the following four ways:
[1]
for (auto &elem : list)
if (its_the_one_that_i_want) {
do_stuff_to_it();
goto done_stuff;
}
add_a_new_one(list);
done_stuff:;
[2]
[&] {
for (auto &elem : list)
if (its_the_one_that_i_want) {
do_stuff_to_it();
return;
}
add_a_new_one(list);
}();
[3]
void do_or_add_stuff(auto& list)
{
for (auto &elem : list)
if (its_the_one_that_i_want) {
do_stuff_to_it();
return;
}
add_a_new_one(list);
}
....
do_or_add_stuff();
[4]
bool stuff_done = false;
for (auto &elem : list)
if (its_the_one_that_i_want) {
do_stuff_to_it();
stuff_done = true;
break;
}
if (!stuff_done)
add_a_new_one(list);
The most common is by far [4], whether it is "better" than the others is
arguable.
I would argue that if we are open to changes we should allow the following:
[5]
do_or_add_stuff: {
for (auto &elem : list)
if (its_the_one_that_i_want) {
do_stuff_to_it();
break do_or_add_stuff;
}
add_a_new_one(list);
}
I would argue this is at least strictly better than [1], as goto can create
an arbitrary edge, whereas break can only terminate an enclosing statement.
I don't like for-else. If I say in English "for each A, do B, else do C"
it doesn't have the semantic we want. In fact it has the opposite meaning,
it says if you can't do B for each A, then do C instead. Because of this
ambiguity we should just leave it out of the existing 4 or 5 options.
But regardless, I don't think we're going to get anything passed evolution
in this area, as it is too subjective and heavily populated. Ironically,
it is precisely because everyone uses this part of the language a lot, that
it creates a polarizing effect that blocks progress, because people care
too much about it.
I therefore strongly discourage Markus Grech from pursing a proposal in
this area.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a11c366983acf4c0501e1312a
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=
at, Aug 30, 2014 at 11:54 PM, Richard Smith <span dir=3D"ltr"><<a href=
=3D"mailto:richard@metafoo.co.uk" target=3D"_blank">richard@metafoo.co.uk</=
a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"=
gmail_quote">
<div class=3D"">On Sat, Aug 30, 2014 at 3:10 AM, Markus Grech <span dir=3D"=
ltr"><<a href=3D"mailto:markus.grech@gmail.com" target=3D"_blank">markus=
..grech@gmail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div dir=3D"ltr"><div>On Friday, August 29, 2014 11:16:00 =
PM UTC+2, Richard Smith wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex">
<div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>What would this mean:=
</div><div><br></div><div>=C2=A0 if (x)</div><div>=C2=A0 =C2=A0 for (blah :=
y)</div><div>=C2=A0 =C2=A0 =C2=A0 thing;</div><div>=C2=A0 =C2=A0else</div>=
<div>=C2=A0 =C2=A0 thing;</div></div></div></div>
</blockquote>
</div><div>Ugh, the dangling else problem again. Guess I'll have to use=
a different syntax then. How about for else/while else? <br></div><div><di=
v>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px=
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left=
-style:solid;padding-left:1ex">
<div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><div>Also, pyth=
on has a for-else construct that means something completely different (the =
else block is reached if the loop terminates normally -- not by 'break&=
#39;). I think this is the wrong syntax, even if the functionality is usefu=
l (which I'm unconvinced by, FWIW).</div>
</div></div></div></blockquote></div><div>I fail to see the usefulness in p=
ythons semantics, but I will do more investigation. Thanks for the hint.</d=
iv></div></blockquote><div><br></div></div><div>Here's a fairly typical=
usage pattern:</div>
<div><br></div><div>for (auto &elem : list) {</div><div>=C2=A0 if (its_=
the_one_that_i_want) {</div><div>=C2=A0 =C2=A0 do_stuff_to_it();</div><div>=
=C2=A0 =C2=A0 break;=C2=A0</div><div>=C2=A0 }</div><div>} else {</div><div>=
=C2=A0 add_a_new_one(list);=C2=A0</div></div>
</div></div></blockquote><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);=
border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D"gm=
ail_extra">
<div class=3D"gmail_quote"><div>}</div></div></div></div></blockquote><div>=
<br></div><div>It can be done in one of the following four ways:</div><div>=
<br></div><div>[1]</div><div>=C2=A0</div></div><div>for (auto &elem : l=
ist)</div>
<div>=C2=A0 =C2=A0 if (its_the_one_that_i_want) {</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 do_stuff_to_it();</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 goto =
done_stuff;=C2=A0</div><div>=C2=A0 =C2=A0 }</div><div>add_a_new_one(list);<=
br></div><div>done_stuff:;</div><div><br></div><div>[2]</div><div>
<br></div><div>[&] {</div><div><div>=C2=A0 =C2=A0 for (auto &elem :=
list)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (its_the_one_that_i_want) {=
</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0do_stuff_to_it();</div>=
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;=C2=A0</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 add_a_new_one(list);<br>
</div><div>}();</div></div><div><br></div><div>[3]</div><div><br></div><div=
>void do_or_add_stuff(auto& list)</div><div>{</div><div>=C2=A0 =C2=A0 f=
or (auto &elem : list)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (its_th=
e_one_that_i_want) {</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 do_stuff_to_it();</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;=C2=A0</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 add_a_new_one(list);</div><div>=
}</div><div><br></div><div>...</div><div><br></div><div>do_or_add_stuff();<=
/div><div><br></div>
<div>[4]</div><div><br></div><div>bool stuff_done =3D false;</div><div><br>=
</div><div><div>for (auto &elem : list)</div><div>=C2=A0 =C2=A0 if (its=
_the_one_that_i_want) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 do_stuff_to_i=
t();</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 stuff_done =3D true;</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 break;</div><div>=C2=A0 =C2=A0 }<br></div>=
</div><div><br></div><div>if (!stuff_done)</div><div>=C2=A0 =C2=A0 add_a_ne=
w_one(list);</div><div><br></div><div>The most common is by far [4], whethe=
r it is "better" than the others is arguable.</div>
<div><br></div><div>I would argue that if we are open to changes we should =
allow the following:</div><div><br></div><div>[5]</div><div><br></div><div>=
do_or_add_stuff: {</div><div><div>=C2=A0 =C2=A0 for (auto &elem : list)=
</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (its_the_one_that_i_want) {</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 do_stuff_to_it();</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break do_or_add_stuff;=C2=A0</div><d=
iv>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 add_a_new_one(list=
);</div></div><div>}</div><div><br></div>
<div>I would argue this is at least strictly better than [1], as goto can c=
reate an arbitrary edge, whereas break can only terminate an enclosing stat=
ement.</div><div><br></div><div>I don't like for-else. =C2=A0If I say i=
n English "for each A, do B, else do C" it doesn't have the s=
emantic we want. =C2=A0In fact it has the opposite meaning, it says if you =
can't do B for each A, then do C instead. =C2=A0Because of this ambigui=
ty we should just leave it out of the existing 4 or 5 options.</div>
<div><br></div><div>But regardless, I don't think we're going to ge=
t anything passed evolution in this area, as it is too subjective and heavi=
ly populated. =C2=A0Ironically, it is precisely because everyone uses this =
part of the language a lot, that it creates a polarizing effect that blocks=
progress, because people care too much about it.</div>
<div><br></div><div>I therefore strongly discourage Markus Grech from pursi=
ng a proposal in this area.</div><div><br></div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c366983acf4c0501e1312a--
.
Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Sun, 31 Aug 2014 13:41:38 +0200
Raw View
On Fri, Aug 29, 2014 at 09:45:44AM -0700, Markus Grech wrote:
> Hi, I would like to gather some initial feedback about my ideas before
> writing proposals.
>
> My second idea is unify the do-notation in loops by allowing it to be
> applied to any loop. The do-while loop is no longer a special looping
> construct, it's a regular while loop with a do-block and an empty statement
> as its body.
> do stuff1;
> while(cond)
> stuff2;
> The semantics of this would be equivalent to:
> for(;;)
> {
> stuff1;
>
> if(!(cond))
> break;
>
> stuff2;
> }
> Similarly, this construct is allowed for for- and foreach-loops.
>
> An example usage of this would be to write a command prompt:
> do std::cout << "> ";
> for(std::string line; std::getline(std::cin, line);)
> process(line);
> It could also be useful to add debug output to an existing read-loop.
> The variable defined in the for-loop is not accessible in the do-block, but
> initialized before anything else.
Thinking more about it this one also breaks existing code:
do for (;conditionA;) statementA(); while (conditionB);
With your proposal that means
do
for (conditionA)
statementA();
while (conditionB)
;
whereas today it means
do
for (conditionA)
statementA();
while (conditionB);
Breaking existing code is bad.
/MF
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Markus Grech <markus.grech@gmail.com>
Date: Sun, 31 Aug 2014 04:47:58 -0700 (PDT)
Raw View
------=_Part_1466_541168741.1409485678376
Content-Type: text/plain; charset=UTF-8
It would not, because a statement must be present after the do.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1466_541168741.1409485678376
Content-Type: text/html; charset=UTF-8
<div dir="ltr">It would not, because a statement must be present after the do.<br></div>
<p></p>
-- <br />
<br />
--- <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 email to <a href="mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
------=_Part_1466_541168741.1409485678376--
.
Author: David Krauss <potswa@gmail.com>
Date: Sun, 31 Aug 2014 22:16:49 +0800
Raw View
--Apple-Mail=_5B1957E4-4A3C-4F87-B931-FB06A36450F0
Content-Type: text/plain; charset=ISO-8859-1
On 2014-08-31, at 7:47 PM, Markus Grech <markus.grech@gmail.com> wrote:
> It would not, because a statement must be present after the do.
More precisely, your proposal allows a statement to precede the semicolon in a do-loop, or while to be changed to for, but it's non-breaking because it doesn't change the association of statements with control clauses.
I've always missed this feature. It's inconvenient when a loop condition outgrows a subexpression. The only language I know with such a feature (excluding goto) is Forth, but it's rather free-form and lacks distinct statements.
But as Andrew said, the current committee has expressed strong distaste for control structure adjustment.
Is anyone familiar with the C (WG14) process and proposals? Have they already voted for or against such things?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--Apple-Mail=_5B1957E4-4A3C-4F87-B931-FB06A36450F0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;08–31, at 7:47 PM, Markus Grech <<a href=3D"mailto:markus.gr=
ech@gmail.com">markus.grech@gmail.com</a>> wrote:</div><br class=3D"Appl=
e-interchange-newline"><blockquote type=3D"cite"><div dir=3D"ltr">It would =
not, because a statement must be present after the do.<br></div></blockquot=
e><br></div><div>More precisely, your proposal allows a statement to preced=
e the semicolon in a <font face=3D"Courier">do</font>-loop, or <font face=
=3D"Courier">while</font> to be changed to <font face=3D"Courier">for</font=
>, but it’s non-breaking because it doesn’t change the associat=
ion of statements with control clauses.</div><br><div>I’ve always mis=
sed this feature. It’s inconvenient when a loop condition outgrows a =
subexpression. The only language I know with such a feature (excluding goto=
) is Forth, but it’s rather free-form and lacks distinct statements.<=
/div><div><br></div><div>But as Andrew said, the current committee has expr=
essed strong distaste for control structure adjustment.</div><div><br></div=
><div>Is anyone familiar with the C (WG14) process and proposals? Have they=
already voted for or against such things?</div><div><br></div></body></htm=
l>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_5B1957E4-4A3C-4F87-B931-FB06A36450F0--
.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Sun, 31 Aug 2014 23:38:45 -0700 (PDT)
Raw View
------=_Part_1570_1708708274.1409553525356
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Of your four initial solutions number 1 uses a goto which is of course=20
possible but is commonly thought of as bad practice as it can easily create=
=20
spaghetti code. Number 2 and 3 are only applicable if
you can do a return. Number 4 is what the suggestion is all about avoiding=
=20
and I agree that it would be very nice if we could. Number 5 I don't think=
=20
is possible as it requires break to be able to break out of a normal block=
=20
statement. This would break (sic!) lots of existing code where break is=20
supposed to leave a loop or switch outside the block statement.
Instead of all this I would suggest that loops *return* a bool which is=20
true if the loop was broken out of and false if it ran to completion.
bool ok =3D for (...)
stuff1;
if (!ok)
add_one_more();
=20
You could of course nest the for inside the if condition but to my=20
untrained eye this looks ugly.
Den s=C3=B6ndagen den 31:e augusti 2014 kl. 01:33:12 UTC+2 skrev Andrew Tom=
azos:
>
> On Sat, Aug 30, 2014 at 11:54 PM, Richard Smith <ric...@metafoo.co.uk=20
> <javascript:>> wrote:
>
>> On Sat, Aug 30, 2014 at 3:10 AM, Markus Grech <markus...@gmail.com=20
>> <javascript:>> wrote:
>>
>>> On Friday, August 29, 2014 11:16:00 PM UTC+2, Richard Smith wrote:
>>>
>>>> What would this mean:
>>>>
>>>> if (x)
>>>> for (blah : y)
>>>> thing;
>>>> else
>>>> thing;
>>>>
>>> Ugh, the dangling else problem again. Guess I'll have to use a differen=
t=20
>>> syntax then. How about for else/while else?=20
>>> =20
>>>
>>>> Also, python has a for-else construct that means something completely=
=20
>>>> different (the else block is reached if the loop terminates normally -=
- not=20
>>>> by 'break'). I think this is the wrong syntax, even if the functionali=
ty is=20
>>>> useful (which I'm unconvinced by, FWIW).
>>>>
>>> I fail to see the usefulness in pythons semantics, but I will do more=
=20
>>> investigation. Thanks for the hint.
>>>
>>
>> Here's a fairly typical usage pattern:
>>
>> for (auto &elem : list) {
>> if (its_the_one_that_i_want) {
>> do_stuff_to_it();
>> break;=20
>> }
>> } else {
>> add_a_new_one(list);=20
>>
> }
>>
>
> It can be done in one of the following four ways:
>
> [1]
> =20
> for (auto &elem : list)
> if (its_the_one_that_i_want) {
> do_stuff_to_it();
> goto done_stuff;=20
> }
> add_a_new_one(list);
> done_stuff:;
>
> [2]
>
> [&] {
> for (auto &elem : list)
> if (its_the_one_that_i_want) {
> do_stuff_to_it();
> return;=20
> }
> add_a_new_one(list);
> }();
>
> [3]
>
> void do_or_add_stuff(auto& list)
> {
> for (auto &elem : list)
> if (its_the_one_that_i_want) {
> do_stuff_to_it();
> return;=20
> }
> add_a_new_one(list);
> }
>
> ...
>
> do_or_add_stuff();
>
> [4]
>
> bool stuff_done =3D false;
>
> for (auto &elem : list)
> if (its_the_one_that_i_want) {
> do_stuff_to_it();
> stuff_done =3D true;
> break;
> }
>
> if (!stuff_done)
> add_a_new_one(list);
>
> The most common is by far [4], whether it is "better" than the others is=
=20
> arguable.
>
> I would argue that if we are open to changes we should allow the followin=
g:
>
> [5]
>
> do_or_add_stuff: {
> for (auto &elem : list)
> if (its_the_one_that_i_want) {
> do_stuff_to_it();
> break do_or_add_stuff;=20
> }
> add_a_new_one(list);
> }
>
> I would argue this is at least strictly better than [1], as goto can=20
> create an arbitrary edge, whereas break can only terminate an enclosing=
=20
> statement.
>
> I don't like for-else. If I say in English "for each A, do B, else do C"=
=20
> it doesn't have the semantic we want. In fact it has the opposite meanin=
g,=20
> it says if you can't do B for each A, then do C instead. Because of this=
=20
> ambiguity we should just leave it out of the existing 4 or 5 options.
>
> But regardless, I don't think we're going to get anything passed evolutio=
n=20
> in this area, as it is too subjective and heavily populated. Ironically,=
=20
> it is precisely because everyone uses this part of the language a lot, th=
at=20
> it creates a polarizing effect that blocks progress, because people care=
=20
> too much about it.
>
> I therefore strongly discourage Markus Grech from pursing a proposal in=
=20
> this area.
>
>
--=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_1570_1708708274.1409553525356
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Of your four initial solutions number 1 uses a goto which =
is of course possible but is commonly thought of as bad practice as it can =
easily create spaghetti code. Number 2 and 3 are only applicable if<div>you=
can do a return. Number 4 is what the suggestion is all about avoiding and=
I agree that it would be very nice if we could. Number 5 I don't think is =
possible as it requires break to be able to break out of a normal block sta=
tement. This would break (sic!) lots of existing code where break is suppos=
ed to leave a loop or switch outside the block statement.</div><div><br></d=
iv><div>Instead of all this I would suggest that loops <i>return</i> a=
bool which is true if the loop was broken out of and false if it ran to co=
mpletion.</div><div><br></div><div>bool ok =3D for (...)</div><div> &=
nbsp; stuff1;</div><div><br></div><div>if (!ok)</div><div> add=
_one_more();</div><div><span style=3D"font-size: 13px;"> =
</span><br></div><div>You could of course nest the for inside the if condit=
ion but to my untrained eye this looks ugly.</div><div><br>Den s=C3=B6ndage=
n den 31:e augusti 2014 kl. 01:33:12 UTC+2 skrev Andrew Tomazos:<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 Sat, Aug 30, 2014 at 11:54 PM, Richard Smith <span dir=3D"ltr">&=
lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"wL5C6=
J9TFYAJ" onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"=
this.href=3D'javascript:';return true;">ric...@metafoo.co.uk</a>></span>=
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote">
<div>On Sat, Aug 30, 2014 at 3:10 AM, Markus Grech <span dir=3D"ltr"><<a=
href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"wL5C6J9TFY=
AJ" onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.=
href=3D'javascript:';return true;">markus...@gmail.com</a>></span> wrote=
:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div dir=3D"ltr"><div>On Friday, August 29, 2014 11:16:00 =
PM UTC+2, Richard Smith wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex">
<div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>What would this mean:=
</div><div><br></div><div> if (x)</div><div> for (blah :=
y)</div><div> thing;</div><div> else</div>=
<div> thing;</div></div></div></div>
</blockquote>
</div><div>Ugh, the dangling else problem again. Guess I'll have to use a d=
ifferent syntax then. How about for else/while else? <br></div><div><div>&n=
bsp;</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8=
ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-sty=
le:solid;padding-left:1ex">
<div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><div>Also, pyth=
on has a for-else construct that means something completely different (the =
else block is reached if the loop terminates normally -- not by 'break'). I=
think this is the wrong syntax, even if the functionality is useful (which=
I'm unconvinced by, FWIW).</div>
</div></div></div></blockquote></div><div>I fail to see the usefulness in p=
ythons semantics, but I will do more investigation. Thanks for the hint.</d=
iv></div></blockquote><div><br></div></div><div>Here's a fairly typical usa=
ge pattern:</div>
<div><br></div><div>for (auto &elem : list) {</div><div> if (its_=
the_one_that_i_want) {</div><div> do_stuff_to_it();</div><div>=
break; </div><div> }</div><div>} else {</div><div>=
add_a_new_one(list); </div></div>
</div></div></blockquote><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);=
border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div>
<div class=3D"gmail_quote"><div>}</div></div></div></div></blockquote><div>=
<br></div><div>It can be done in one of the following four ways:</div><div>=
<br></div><div>[1]</div><div> </div></div><div>for (auto &elem : l=
ist)</div>
<div> if (its_the_one_that_i_want) {</div><div> &=
nbsp; do_stuff_to_it();</div><div> goto d=
one_stuff; </div><div> }</div><div>add_a_new_one(list);<b=
r></div><div>done_stuff:;</div><div><br></div><div>[2]</div><div>
<br></div><div>[&] {</div><div><div> for (auto &elem :=
list)</div><div> if (its_the_one_that_i_want) {=
</div><div> do_stuff_to_it();</div>=
<div> return; </div><div> =
; }</div><div> add_a_new_one(list);<br>
</div><div>}();</div></div><div><br></div><div>[3]</div><div><br></div><div=
>void do_or_add_stuff(auto& list)</div><div>{</div><div> f=
or (auto &elem : list)</div><div> if (its_th=
e_one_that_i_want) {</div>
<div> do_stuff_to_it();</div><div>=
return; </div><div> &nb=
sp; }</div><div> add_a_new_one(list);</div><div>=
}</div><div><br></div><div>...</div><div><br></div><div>do_or_add_stuff();<=
/div><div><br></div>
<div>[4]</div><div><br></div><div>bool stuff_done =3D false;</div><div><br>=
</div><div><div>for (auto &elem : list)</div><div> if (its=
_the_one_that_i_want) {</div><div> do_stuff_to_i=
t();</div><div> stuff_done =3D true;</div>
<div> break;</div><div> }<br></div>=
</div><div><br></div><div>if (!stuff_done)</div><div> add_a_ne=
w_one(list);</div><div><br></div><div>The most common is by far [4], whethe=
r it is "better" than the others is arguable.</div>
<div><br></div><div>I would argue that if we are open to changes we should =
allow the following:</div><div><br></div><div>[5]</div><div><br></div><div>=
do_or_add_stuff: {</div><div><div> for (auto &elem : list)=
</div>
<div> if (its_the_one_that_i_want) {</div><div>&=
nbsp; do_stuff_to_it();</div><div> =
break do_or_add_stuff; </div><div>=
}</div><div> add_a_new_one(list);<=
/div></div><div>}</div><div><br></div>
<div>I would argue this is at least strictly better than [1], as goto can c=
reate an arbitrary edge, whereas break can only terminate an enclosing stat=
ement.</div><div><br></div><div>I don't like for-else. If I say in En=
glish "for each A, do B, else do C" it doesn't have the semantic we want. &=
nbsp;In fact it has the opposite meaning, it says if you can't do B for eac=
h A, then do C instead. Because of this ambiguity we should just leav=
e it out of the existing 4 or 5 options.</div>
<div><br></div><div>But regardless, I don't think we're going to get anythi=
ng passed evolution in this area, as it is too subjective and heavily popul=
ated. Ironically, it is precisely because everyone uses this part of =
the language a lot, that it creates a polarizing effect that blocks progres=
s, because people care too much about it.</div>
<div><br></div><div>I therefore strongly discourage Markus Grech from pursi=
ng a proposal in this area.</div><div><br></div></div></div>
</blockquote></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1570_1708708274.1409553525356--
.
Author: Markus Grech <markus.grech@gmail.com>
Date: Fri, 5 Sep 2014 03:48:11 -0700 (PDT)
Raw View
------=_Part_7_1195831065.1409914091183
Content-Type: text/plain; charset=UTF-8
Idea 3 is probably going to create a huge controversy, I will therefore not
pursue it any further.
One case where i personally found that idea 1 is helpful is input with
standard streams. The following code is missing parenthesis, but is
perfectly legal C++:
char c;
if(!stream >> c)
...
This bug has caught me several times now. If we implement idea 1 and start
using it by default, this can't happen anymore.
As for idea 2, the changes to the grammar are minimal and a compiler
implementation shouldn't be too hard from my own experience. It adds
control flow constructs that make code more readable in some code and I
hate having to resort to for(;;).
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_7_1195831065.1409914091183
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Idea 3 is probably going to create a huge controversy, I w=
ill therefore not pursue it any further.<br><br>One case where i personally=
found that idea 1 is helpful is input with standard streams. The following=
code is missing parenthesis, but is perfectly legal C++:<br><div class=3D"=
prettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: r=
gb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break=
-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> c</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">if</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(!</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">stream </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">>></span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> c</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nb=
sp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">...</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></=
div></code></div>This bug has caught me several times now. If we implement =
idea 1 and start using it by default, this can't happen anymore.<br><br>As =
for idea 2, the changes to the grammar are minimal and a compiler implement=
ation shouldn't be too hard from my own experience. It adds control flow co=
nstructs that make code more readable in some code and I hate having to res=
ort to for(;;).<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_7_1195831065.1409914091183--
.
Author: Sean Middleditch <sean.middleditch@gmail.com>
Date: Fri, 5 Sep 2014 15:52:05 -0700 (PDT)
Raw View
------=_Part_5208_1340413137.1409957525314
Content-Type: text/plain; charset=UTF-8
On Friday, September 5, 2014 3:48:11 AM UTC-7, Markus Grech wrote:
>
> Idea 3 is probably going to create a huge controversy, I will therefore
> not pursue it any further.
>
> One case where i personally found that idea 1 is helpful is input with
> standard streams. The following code is missing parenthesis, but is
> perfectly legal C++:
> char c;
>
> if(!stream >> c)
> ...
> This bug has caught me several times now. If we implement idea 1 and start
> using it by default, this can't happen anymore.
>
I don't see how allowing you to move the ! one character left is going to
reduce the likelihood of bugs. If anything, it seems like it makes it even
easier to make simple mistakes.
This is probably something that a compiler could generate a warning for
similar to how misuses of = vs == are usually warnings these days.
>
> As for idea 2, the changes to the grammar are minimal and a compiler
> implementation shouldn't be too hard from my own experience. It adds
> control flow constructs that make code more readable in some code and I
> hate having to resort to for(;;).
>
In constructs like
int x;
do
foo(x);
while (int x = bar())
cout<<x;
which x gets passed to foo()? Would this be equivalent to:
int x;
for(;;) {
foo(x);
{
int x = bar();
if(!x)
break;
cout<<x;
}
}
?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_5208_1340413137.1409957525314
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>On Friday, September 5, 2014 3:48:11 AM UTC-7, Markus=
Grech wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
Idea 3 is probably going to create a huge controversy, I will therefore not=
pursue it any further.<br><br>One case where i personally found that idea =
1 is helpful is input with standard streams. The following code is missing =
parenthesis, but is perfectly legal C++:<br><div style=3D"background-color:=
rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-wi=
dth:1px;word-wrap:break-word"><code><div><span style=3D"color:#008">char</s=
pan><span style=3D"color:#000"> c</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"><br><br></span><span style=3D"color:#008">if</sp=
an><span style=3D"color:#660">(!</span><span style=3D"color:#000">stream </=
span><span style=3D"color:#660">>></span><span style=3D"color:#000"> =
c</span><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>&=
nbsp; </span><span style=3D"color:#660">...</span><span style=3D"col=
or:#000"><br></span></div></code></div>This bug has caught me several times=
now. If we implement idea 1 and start using it by default, this can't happ=
en anymore.<br></div></blockquote><div><br></div><div>I don't see how allow=
ing you to move the ! one character left is going to reduce the likelihood =
of bugs. If anything, it seems like it makes it even easier to make simple =
mistakes.<div><br></div><div>This is probably something that a compiler cou=
ld generate a warning for similar to how misuses of =3D vs =3D=3D are usual=
ly warnings these days.<br></div></div><div> </div><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"><br>As for idea 2, the changes=
to the grammar are minimal and a compiler implementation shouldn't be too =
hard from my own experience. It adds control flow constructs that make code=
more readable in some code and I hate having to resort to for(;;).<br></di=
v></blockquote><div><br></div><div>In constructs like</div></div><div><br><=
/div><div> int x;</div><div> do</div><div> foo(x);=
</div><div> while (int x =3D bar())</div><div> cout<&=
lt;x;</div><div><br></div><div>which x gets passed to foo()? Would this be =
equivalent to:</div><div><br></div><div> int x;</div><div> for(=
;;) {</div><div> foo(x);</div><div> {<br></div><d=
iv> int x =3D bar();</div><div> if(=
!x)</div><div> break;</div><div> &n=
bsp; cout<<x;</div><div> }</div><div> }</div><div>=
<br></div><div>?</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_5208_1340413137.1409957525314--
.
Author: Markus Grech <markus.grech@gmail.com>
Date: Sat, 6 Sep 2014 00:46:41 -0700 (PDT)
Raw View
------=_Part_16_825571039.1409989601246
Content-Type: text/plain; charset=UTF-8
On Saturday, September 6, 2014 12:52:05 AM UTC+2, Sean Middleditch wrote:
> I don't see how allowing you to move the ! one character left is going to
> reduce the likelihood of bugs. If anything, it seems like it makes it even
> easier to make simple mistakes.
>
How would it make it easier to make mistakes?
> This is probably something that a compiler could generate a warning for
> similar to how misuses of = vs == are usually warnings these days.
>
Not sure about that, as the code is still broken if you initialize the
variable.
> In constructs like
>
> int x;
> do
> foo(x);
> while (int x = bar())
> cout<<x;
>
> which x gets passed to foo()? Would this be equivalent to:
>
> int x;
> for(;;) {
> foo(x);
> {
> int x = bar();
> if(!x)
> break;
> cout<<x;
> }
> }
>
> ?
>
I would argue that - for consistency with the rest of the language - you
cannot access a variable lexically before it has been declared. Thus it
would pass the first x to foo, like in your example. Current do-while does
it that way as well. However, I would also say that people shouldn't write
code like that - it is very confusing.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_16_825571039.1409989601246
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Saturday, September 6, 2014 12:52:05 AM UTC+2, =
Sean Middleditch wrote:<br><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>I don't see how allowing you to move the ! one char=
acter left is going to reduce the likelihood of bugs. If anything, it seems=
like it makes it even easier to make simple mistakes.</div></div></div></b=
lockquote><div>How would it make it easier to make mistakes?<br> <br><=
/div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><di=
v><div>This is probably something that a compiler could generate a warning =
for similar to how misuses of =3D vs =3D=3D are usually warnings these days=
..<br></div></div></div></div></blockquote><div>Not sure about that, as the =
code is still broken if you initialize the variable. <br> <br></div><b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div></div=
><div>In constructs like</div><br></div><div> int x;</div><div> =
do</div><div> foo(x);</div><div> while (int x =3D bar()=
)</div><div> cout<<x;</div><div><br></div><div>which x g=
ets passed to foo()? Would this be equivalent to:</div><div><br></div><div>=
int x;</div><div> for(;;) {</div><div> foo(x);</d=
iv><div> {<br></div><div> int x =3D bar();=
</div><div> if(!x)</div><div>  =
; break;</div><div> cout<<x;</div><div> &nb=
sp; }</div><div> }</div><div><br></div><div>?</div></div></blockquote=
><div>I would argue that - for consistency with the rest of the language - =
you cannot access a variable lexically before it has been declared. Thus it=
would pass the first x to foo, like in your example. Current do-while does=
it that way as well. However, I would also say that people shouldn't write=
code like that - it is very confusing. <br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_16_825571039.1409989601246--
.
Author: Sean Middleditch <sean@middleditch.us>
Date: Sat, 6 Sep 2014 08:24:45 -0700
Raw View
On Sat, Sep 6, 2014 at 12:46 AM, Markus Grech <markus.grech@gmail.com> wrote:
>
>
> On Saturday, September 6, 2014 12:52:05 AM UTC+2, Sean Middleditch wrote:
>>
>> I don't see how allowing you to move the ! one character left is going to
>> reduce the likelihood of bugs. If anything, it seems like it makes it even
>> easier to make simple mistakes.
>
> How would it make it easier to make mistakes?
Moving a character left or right by one is one of the more common
typos (and hey, it's an "off by one" error, our old nemesis :p ). It
also tends to look just right enough to be easy to miss when reviewing
code.
>
>>
>> This is probably something that a compiler could generate a warning for
>> similar to how misuses of = vs == are usually warnings these days.
>
> Not sure about that, as the code is still broken if you initialize the
> variable.
My point is, if(x=y) generates a warning on almost every compiler.
if(!str>>x) could (should?) as well. We didn't need new syntax to
avoid mistakes with = vs == and I don't think we need it for bitwise
operations on boolean values (which is what this turns into rather
than a stream operation).
>
> I would argue that - for consistency with the rest of the language - you
> cannot access a variable lexically before it has been declared. Thus it
> would pass the first x to foo, like in your example. Current do-while does
That certainly makes the most sense. I'd just want to recommend you
spell out the details like this in any paper written for the feature.
> it that way as well. However, I would also say that people shouldn't write
> code like that - it is very confusing.
Well, sure, but it's not the standard's job to teach good programming
habits but rather just to provide clear, unambiguous, and consistent
rules. :)
--
Sean Middleditch
http://seanmiddleditch.com
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Fernando Pelliccioni <fpelliccioni@gmail.com>
Date: Sat, 6 Sep 2014 19:24:38 -0300
Raw View
--089e01493a0c22d48b05026d0d4e
Content-Type: text/plain; charset=UTF-8
On Saturday, September 6, 2014, Sean Middleditch <sean.middleditch@gmail.com>
wrote:
> On Friday, September 5, 2014 3:48:11 AM UTC-7, Markus Grech wrote:
>>
>> Idea 3 is probably going to create a huge controversy, I will therefore
>> not pursue it any further.
>>
>> One case where i personally found that idea 1 is helpful is input with
>> standard streams. The following code is missing parenthesis, but is
>> perfectly legal C++:
>> char c;
>>
>> if(!stream >> c)
>> ...
>> This bug has caught me several times now. If we implement idea 1 and
>> start using it by default, this can't happen anymore.
>>
>
> I don't see how allowing you to move the ! one character left is going to
> reduce the likelihood of bugs. If anything, it seems like it makes it even
> easier to make simple mistakes.
>
>
> This is probably something that a compiler could generate a warning for
> similar to how misuses of = vs == are usually warnings these days.
>
For readability you could use the "not" keyword
if (not b) do_something();
>
>
>>
>> As for idea 2, the changes to the grammar are minimal and a compiler
>> implementation shouldn't be too hard from my own experience. It adds
>> control flow constructs that make code more readable in some code and I
>> hate having to resort to for(;;).
>>
>
> In constructs like
>
> int x;
> do
> foo(x);
> while (int x = bar())
> cout<<x;
>
> which x gets passed to foo()? Would this be equivalent to:
>
> int x;
> for(;;) {
> foo(x);
> {
> int x = bar();
> if(!x)
> break;
> cout<<x;
> }
> }
>
> ?
>
> --
>
> ---
> 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
> <javascript:_e(%7B%7D,'cvml','std-proposals%2Bunsubscribe@isocpp.org');>.
> To post to this group, send email to std-proposals@isocpp.org
> <javascript:_e(%7B%7D,'cvml','std-proposals@isocpp.org');>.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--089e01493a0c22d48b05026d0d4e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<br><br>On Saturday, September 6, 2014, Sean Middleditch <<a href=3D"mai=
lto:sean.middleditch@gmail.com">sean.middleditch@gmail.com</a>> wrote:<b=
r><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>On Friday, September=
5, 2014 3:48:11 AM UTC-7, Markus Grech wrote:<blockquote class=3D"gmail_qu=
ote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr">Idea 3 is probably going to create a huge contr=
oversy, I will therefore not pursue it any further.<br><br>One case where i=
personally found that idea 1 is helpful is input with standard streams. Th=
e following code is missing parenthesis, but is perfectly legal C++:<br><di=
v 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><div><span =
style=3D"color:#008">char</span><span style=3D"color:#000"> c</span><span s=
tyle=3D"color:#660">;</span><span style=3D"color:#000"><br><br></span><span=
style=3D"color:#008">if</span><span style=3D"color:#660">(!</span><span st=
yle=3D"color:#000">stream </span><span style=3D"color:#660">>></span>=
<span style=3D"color:#000"> c</span><span style=3D"color:#660">)</span><spa=
n style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">=
....</span><span style=3D"color:#000"><br></span></div></code></div>This bug=
has caught me several times now. If we implement idea 1 and start using it=
by default, this can't happen anymore.<br></div></blockquote><div><br>=
</div><div>I don't see how allowing you to move the ! one character lef=
t is going to reduce the likelihood of bugs. If anything, it seems like it =
makes it even easier to make simple mistakes.</div><div><br><div><br></div>=
<div>This is probably something that a compiler could generate a warning fo=
r similar to how misuses of =3D vs =3D=3D are usually warnings these days.<=
br></div></div></div></div></blockquote><div><br></div><div>For readability=
you could use the "not" keyword</div><div><br></div><div>if (not=
b) do_something();<span></span>=C2=A0</div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=
<div dir=3D"ltr"><div><div>=C2=A0</div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr"><br>As for idea 2, the changes to the grammar are mini=
mal and a compiler implementation shouldn't be too hard from my own exp=
erience. It adds control flow constructs that make code more readable in so=
me code and I hate having to resort to for(;;).<br></div></blockquote><div>=
<br></div><div>In constructs like</div></div><div><br></div><div>=C2=A0 int=
x;</div><div>=C2=A0 do</div><div>=C2=A0 =C2=A0 foo(x);</div><div>=C2=A0 wh=
ile (int x =3D bar())</div><div>=C2=A0 =C2=A0 cout<<x;</div><div><br>=
</div><div>which x gets passed to foo()? Would this be equivalent to:</div>=
<div><br></div><div>=C2=A0 int x;</div><div>=C2=A0 for(;;) {</div><div>=C2=
=A0 =C2=A0 foo(x);</div><div>=C2=A0 =C2=A0 {<br></div><div>=C2=A0 =C2=A0 =
=C2=A0 int x =3D bar();</div><div>=C2=A0 =C2=A0 =C2=A0 if(!x)</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 break;</div><div>=C2=A0 =C2=A0 =C2=A0 cout<<=
x;</div><div>=C2=A0 =C2=A0 }</div><div>=C2=A0 }</div><div><br></div><div>?<=
/div></div>
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:_e(%7B%7D,'cvml','std-proposals%2=
Bunsubscribe@isocpp.org');" target=3D"_blank">std-proposals+unsubscribe=
@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:_e(%7B%7D,'c=
vml','std-proposals@isocpp.org');" target=3D"_blank">std-propos=
als@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</blockquote>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--089e01493a0c22d48b05026d0d4e--
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Thu, 02 Oct 2014 16:00:28 -0400
Raw View
On 2014-08-29 13:20, Magnus Fromreide wrote:
> On Fri, Aug 29, 2014 at 09:45:44AM -0700, Markus Grech wrote:
>> My first idea is to make negated conditions easier to write and read. The
>> extra parenthesis always looked odd to me and negating a condition while
>> editing is like a little pain.
>> I would like to propose that the ! can be put before the parenthesis for
>> the condition in the if and while constructs.
>> if!(cond)
>> while!(cond)
>> This would be a built-in construct in the language.
>
> I assume that it would be permitted to declare variables in the parentheses?
>
> if not (int i = fun())
> { /* Do something with i */ }
I would find this useful; I've had occasions before where I wished I
could do exactly this.
I'm not sure how well allowing the '!' outside the ()'s would go over,
though.
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Thu, 02 Oct 2014 16:08:35 -0400
Raw View
On 2014-09-01 02:38, Bengt Gustafsson wrote:
> Instead of all this I would suggest that loops *return* a bool which is
> true if the loop was broken out of and false if it ran to completion.
>
> bool ok = for (...)
> stuff1;
>
> if (!ok)
> add_one_more();
Huh. That's not a bad idea. What does 'break' "return", though?
Another idea might be to use 'otherwise' instead of 'else'. (This should
probably be supported with 'while' also. Related - and also suggested
previously - could be to have 'then' for code that runs at the end of
the loop iff the loop ran at least once.)
> You could of course nest the for inside the if condition but to my
> untrained eye this looks ugly.
I suspect that this might require an even more involved language
extension (besides being ugly).
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 2 Oct 2014 23:13:59 +0300
Raw View
On 2 October 2014 23:08, Matthew Woehlke <mw_triad@users.sourceforge.net> wrote:
> On 2014-09-01 02:38, Bengt Gustafsson wrote:
>> Instead of all this I would suggest that loops *return* a bool which is
>> true if the loop was broken out of and false if it ran to completion.
>>
>> bool ok = for (...)
>> stuff1;
>>
>> if (!ok)
>> add_one_more();
>
> Huh. That's not a bad idea. What does 'break' "return", though?
>
> Another idea might be to use 'otherwise' instead of 'else'. (This should
> probably be supported with 'while' also. Related - and also suggested
> previously - could be to have 'then' for code that runs at the end of
> the loop iff the loop ran at least once.)
See
http://open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3587.pdf
The paper has been neither rejected nor accepted, more work has been suggested.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: contact@ncomputers.org
Date: Thu, 16 Oct 2014 10:34:34 -0700 (PDT)
Raw View
------=_Part_25_979331243.1413480874846
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Markus,
What do you think? If I were to propose these ideas, should I write a=
=20
> single proposal or three seperate ones?
>
Because the three ideas are good ideas, I think, that to write them=20
together is the best option.
The *for else* syntax is a good idea, for example:
for(it=3D0;it<size;++it){
cout<<array[it]<<endl;
}else{
throw "At least one element is required";
}
It is also a good idea to allow *do ... while ... else loops*.
I'm something special when programming, I like to avoid the execution of=20
avoidable or useles instructions. On this case, to use the *if statement*=
=20
of the *for loop *with an *else block*, could save the execution of one=20
useles *if statement*, for example:
if(size=3D=3D0)throw "At least one element is required";
//Avoidable if statement with your proposal!
for(it=3D0;it<size;++it){
cout<<array[it]<<endl;
}
To your* do...while statement* proposal I want to add one of our ideas,=20
which is to allow the use of *initializers *and after reading your=20
proposals, allow the use of *else*, when the condition is* false*.
if(size=3D=3D0){
throw "At least one element is required!";
}do(unsigned it=3D0){
cout<<array[it];
}while(++it<size){
cout<<',';
}else{
cout<<endl<<it<<" elements streamed"<<endl;
//Note that variables declared inside the initializer, still visible
}
Your idea to negate easier a whole expression is also a good one, because=
=20
it makes *easier* to negate a whole expression. To have less parenthesis=20
could make the code more readable.
//Before:
if(!(a&&b||c&&(b|a)));
while(!(a&&b||c&&(b|a)));
//After:
if!(a&&b||c&&(b|a));
while!(a&&b||c&&(b|a));
Related google group thread=20
<https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-propos=
als/i-0stW2WkXs>
..
Best regards,
ncomputers.org
El viernes, 29 de agosto de 2014 11:45:44 UTC-5, Markus Grech escribi=C3=B3=
:
>
> Hi, I would like to gather some initial feedback about my ideas before=20
> writing proposals.
>
> My first idea is to make negated conditions easier to write and read. The=
=20
> extra parenthesis always looked odd to me and negating a condition while=
=20
> editing is like a little pain.
> I would like to propose that the ! can be put before the parenthesis for=
=20
> the condition in the if and while constructs.
> if!(cond)
> while!(cond)
> This would be a built-in construct in the language.
>
> My second idea is unify the do-notation in loops by allowing it to be=20
> applied to any loop. The do-while loop is no longer a special looping=20
> construct, it's a regular while loop with a do-block and an empty stateme=
nt=20
> as its body.
> do stuff1;
> while(cond)
> stuff2;
> The semantics of this would be equivalent to:
> for(;;)
> {
> stuff1;
>
> if(!(cond))
> break;
>
> stuff2;
> }
> Similarly, this construct is allowed for for- and foreach-loops.
>
> An example usage of this would be to write a command prompt:
> do std::cout << "> ";
> for(std::string line; std::getline(std::cin, line);)
> process(line);
> It could also be useful to add debug output to an existing read-loop.
> The variable defined in the for-loop is not accessible in the do-block,=
=20
> but initialized before anything else.
>
> My third and last idea is to allow loop to have an optional else-block=20
> that would be executed if the condition was never true, that is, the body=
=20
> of the loop has been executed 0 times. This can be especially useful to=
=20
> handle empty containers for example:
> for(auto& elem : container)
> std::cout << elem << '\n';
> else
> std::cout << "no elements\n";
>
> What do you think? If I were to propose these ideas, should I write a=20
> single proposal or three seperate ones?
>
--=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_25_979331243.1413480874846
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Markus,<br><br><blockquote style=3D"margin: 0px 0px 0px 0.=
8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class=
=3D"gmail_quote"> What do you think? If I were to propose=
these ideas, should I write a single proposal or three seperate ones?<br><=
/blockquote><br>Because the three ideas are good ideas, I think, that to wr=
ite them together is the best option.<br><br>The <b>for else</b> syntax is =
a good idea, for example:<br><br><div class=3D"prettyprint" style=3D"backgr=
ound-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-st=
yle: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prett=
yprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D=
"styled-by-prettify">for</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">it</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">it</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">size</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;++</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">it</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">){</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br> cout</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify"><<</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify">array</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">[</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
it</span><span style=3D"color: #660;" class=3D"styled-by-prettify">]<<=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">endl</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=
: #008;" class=3D"styled-by-prettify">else</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">throw</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"st=
yled-by-prettify">"At least one element is required"</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span></div></code></div><br>It is also a good idea =
to allow <b>do ... while ... else loops</b>.<br><br>I'm something special w=
hen programming, I like to avoid the execution of avoidable or useles instr=
uctions. On this case, to use the <b>if statement</b> of the <b>for loop </=
b>with an <b>else block</b>, could save the execution of one useles <b>if s=
tatement</b>, for example:<br><br><div class=3D"prettyprint" style=3D"backg=
round-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-s=
tyle: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pret=
typrint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">if</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">size</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D=3D</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">throw</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #080;" class=3D"styled-by-prettify">"At least one element is required"<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #800;" class=3D"styled-by-prettify">//Avoidable if statement w=
ith your proposal!</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">for</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">it</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</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"styled-by-prettify">it</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">size</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">;++</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">it</span><span style=3D"color: #660;" class=3D"styled-by-prettify">){</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nb=
sp; 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">arra=
y</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">it</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">]<<</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">endl</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span></div></code></div><br>To your<b> do...while s=
tatement</b> proposal I want to add one of our ideas, which is to allow the=
use of <b>initializers </b>and after reading your proposals, allow the use=
of <b>else</b>, when the condition is<b> false</b>.<br><br><div class=3D"p=
rettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">size</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D=3D</span><span style=3D"color: #066;" class=3D=
"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">){</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">throw</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">"A=
t least one element is required!"</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">}</span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
do</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">unsigned</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> it</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">){</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br> cout</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify"><<</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">array</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">[</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">it</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">];</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">while</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(++</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">it</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">size</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">){</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br> cout</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"color:=
#080;" 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></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">}</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">else</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> =
; cout</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>endl</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><&=
lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">it</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify"><<</span>=
<span style=3D"color: #080;" class=3D"styled-by-prettify">" elements stream=
ed"</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><<=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">endl</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: #800;" class=3D"styled-by-prettify">//Note that vari=
ables declared inside the initializer, still visible</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span></div></code></div><br>Your idea to n=
egate easier a whole expression is also a good one, because it makes <b>eas=
ier</b> to negate a whole expression. To have less parenthesis could make t=
he code more readable.<br><br><div class=3D"prettyprint" style=3D"backgroun=
d-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style=
: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettypr=
int"><div class=3D"subprettyprint"><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">//Before:</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">if</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(!(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">a</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&&</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">b</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">||</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">c</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&&(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">b</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">|</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">)));</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
while</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(!(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">a</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&&</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">b</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">||</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">c</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">&&(</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">b</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">|</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">)));</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">//Afte=
r:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">!(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">a</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&&</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">b</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">||</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">c</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&&(</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">b</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">|</span><span style=3D"color: #000;" class=3D"styled-by-prettify">a</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">));</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">while</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">!(</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">a</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&&</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">b</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">||</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">c</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&&(</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>b</span><span style=3D"color: #660;" class=3D"styled-by-prettify">|</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">a</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">));</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br=
>Related <a href=3D"https://groups.google.com/a/isocpp.org/forum/?fromgroup=
s#!topic/std-proposals/i-0stW2WkXs">google group thread</a>.<br><br>Best re=
gards,<br><br><a href=3D"http://ncomputers.org">ncomputers.org</a><br><br>E=
l viernes, 29 de agosto de 2014 11:45:44 UTC-5, Markus Grech escribi=C3=B3:=
<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">Hi, I would l=
ike to gather some initial feedback about my ideas before writing proposals=
..<br><br>My first idea is to make negated conditions easier to write and re=
ad. The extra parenthesis always looked odd to me and negating a condition =
while editing is like a little pain.<br>I would like to propose that the ! =
can be put before the parenthesis for the condition in the if and while con=
structs.<br><div style=3D"background-color:rgb(250,250,250);border-color:rg=
b(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><c=
ode><div><span style=3D"color:#008">if</span><span style=3D"color:#660">!(<=
/span><span style=3D"color:#000">cond</span><span style=3D"color:#660">)</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#008">while<=
/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"><br></sp=
an></div></code></div>This would be a built-in construct in the language.<b=
r><br>My second idea is unify the do-notation in loops by allowing it to be=
applied to any loop. The do-while loop is no longer a special looping cons=
truct, it's a regular while loop with a do-block and an empty statement as =
its body.<br><div style=3D"background-color:rgb(250,250,250);border-color:r=
gb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><=
code><div><span style=3D"color:#008">do</span><span style=3D"color:#000"> s=
tuff1</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br></span><span style=3D"color:#008">while</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"><br> stuff2</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br></span></div></code=
></div>The semantics of this would be equivalent to:<br><div style=3D"backg=
round-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:sol=
id;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#=
008">for</span><span style=3D"color:#660">(;;)</span><span style=3D"color:#=
000"><br></span><span style=3D"color:#660">{</span><span style=3D"color:#00=
0"><br> stuff1</span><span style=3D"color:#660">;</span><span =
style=3D"color:#000"><br><br> </span><span style=3D"color:#008=
">if</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"><=
br> </span><span style=3D"color:#008">break</spa=
n><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br>&nb=
sp; stuff2</span><span style=3D"color:#660">;</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#660">}</span><span style=3D"col=
or:#000"><br></span></div></code></div>Similarly, this construct is allowed=
for for- and foreach-loops.<br><br>An example usage of this would be to wr=
ite a command prompt:<br><div style=3D"background-color:rgb(250,250,250);bo=
rder-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:b=
reak-word"><code><div><span style=3D"color:#008">do</span><span style=3D"co=
lor:#000"> std</span><span style=3D"color:#660">::</span><span style=3D"col=
or:#000">cout </span><span style=3D"color:#660"><<</span><span style=
=3D"color:#000"> </span><span style=3D"color:#080">"> "</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#008">for</span><span style=3D"color:#660">(</span><span style=3D=
"color:#000">std</span><span style=3D"color:#660">::</span><span style=3D"c=
olor:#008">string</span><span style=3D"color:#000"> line</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"> std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">getline</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#000">std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">cin</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> line</span><span style=
=3D"color:#660">);)</span><span style=3D"color:#000"><br> proc=
ess</span><span style=3D"color:#660">(</span><span style=3D"color:#000">lin=
e</span><span style=3D"color:#660">);</span><span style=3D"color:#000"><br>=
</span></div></code></div>It could also be useful to add debug output to an=
existing read-loop.<br>The variable defined in the for-loop is not accessi=
ble in the do-block, but initialized before anything else.<br><br>My third =
and last idea is to allow loop to have an optional else-block that would be=
executed if the condition was never true, that is, the body of the loop ha=
s been executed 0 times. This can be especially useful to handle empty cont=
ainers for example:<br><div style=3D"background-color:rgb(250,250,250);bord=
er-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:bre=
ak-word"><code><div><span style=3D"color:#008">for</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#008">auto</span><span style=3D"color=
:#660">&</span><span style=3D"color:#000"> elem </span><span style=3D"c=
olor:#660">:</span><span style=3D"color:#000"> container</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"><br> std</s=
pan><span style=3D"color:#660">::</span><span style=3D"color:#000">cout </s=
pan><span style=3D"color:#660"><<</span><span style=3D"color:#000"> e=
lem </span><span style=3D"color:#660"><<</span><span style=3D"color:#=
000"> </span><span style=3D"color:#080">'\n'</span><span style=3D"color:#66=
0">;</span><span style=3D"color:#000"><br></span><span style=3D"color:#008"=
>else</span><span style=3D"color:#000"><br> std</span><span st=
yle=3D"color:#660">::</span><span style=3D"color:#000">cout </span><span st=
yle=3D"color:#660"><<</span><span style=3D"color:#000"> </span><span =
style=3D"color:#080">"no elements\n"</span><span style=3D"color:#660">;</sp=
an><span style=3D"color:#000"><br></span></div></code></div><br>What do you=
think? If I were to propose these ideas, should I write a single proposal =
or three seperate ones?<br></div></blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_25_979331243.1413480874846--
.