Topic: Variable declarations inside test before block


Author: squelart@gmail.com
Date: Tue, 2 Dec 2014 20:21:27 -0800 (PST)
Raw View
------=_Part_622_575655055.1417580487414
Content-Type: multipart/alternative;
 boundary="----=_Part_623_620679650.1417580487414"

------=_Part_623_620679650.1417580487414
Content-Type: text/plain; charset=UTF-8

(First time here, please let me know if I'm doing anything wrong!)

Just a quick idea I couldn't find elsewhere with a quick search, I was
wondering if it had already been proposed and/or rejected:

Would it be possible and useful to allow variable declarations inside a
test preceding a block, and make these variables visible inside the
remainder of the test and the block?
(The "remainder of the test" part might be going too far?)
The goal is to avoid polluting a block with variables that are really only
needed inside an inner block.

E.g.:
if ((auto total < (auto max = getMax()) - (auto buffer = max / 3)) > 1) {
    // 'total', 'max' and 'buffer' are visible in this block and destructed
at the end.
}

while (nullptr != (void* buffer = malloc(8))) { foo(buffer); }

for (int i = 0; i < (int end = 10); ++i) { cout << end - i; }

switch (char c = getchar()) { case '\0': break; default: cout << c; }

auto f = (P* p = maybeP()) ? p->foo() : 0; // Too far again?

Any pointers/suggestions/criticisms welcome.
I'd be happy to work on it further if there's any interest.

Cheers,
Gerald

--

---
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_623_620679650.1417580487414
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">(First time here, please let me know if I'm doing anything=
 wrong!)<br><br>Just a quick idea I couldn't find elsewhere with a quick se=
arch, I was wondering if it had already been proposed and/or rejected:<br><=
br>Would it be possible and useful to allow variable declarations inside a =
test preceding a block, and make these variables visible inside the remaind=
er of the test and the block?<br>(The "remainder of the test" part might be=
 going too far?)<br>The goal is to avoid polluting a block with variables t=
hat are really only needed inside an inner block.<br><br>E.g.:<br><div clas=
s=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-col=
or: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: =
break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">((</span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> total </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">aut=
o</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> max </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> getMax</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">())</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">-</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> buffer </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> max </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">/</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">))</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #800;" class=3D"styled-by-prettify">// 'total', 'max' an=
d 'buffer' are visible in this block and destructed at the end.</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><br></span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">while</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">nullptr</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">!=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> buffer </span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> malloc</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"st=
yled-by-prettify">8</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)))</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">buffer</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">for</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> i </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #06=
6;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> i </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">end</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by=
-prettify">10</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">++</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">i</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> cout </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">end</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">-</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> i</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">switch</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">char</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> c </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> getchar</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">())</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">case</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">=
'\0'</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">break</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">default</span><span style=3D"color: #660;" cla=
ss=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-=
by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> c</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </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><br></span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> f </span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">P</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> p </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> maybeP</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">())</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">?</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> p</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">-&gt;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">foo</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">// Too far again?</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span></div></code></div><br>Any pointers/s=
uggestions/criticisms welcome.<br>I'd be happy to work on it further if the=
re's any interest.<br><br>Cheers,<br>Gerald<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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
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_623_620679650.1417580487414--
------=_Part_622_575655055.1417580487414--

.


Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Wed, 3 Dec 2014 00:37:24 -0800 (PST)
Raw View
------=_Part_110_1830880989.1417595844597
Content-Type: multipart/alternative;
 boundary="----=_Part_111_323604260.1417595844597"

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



W dniu =C5=9Broda, 3 grudnia 2014 05:21:27 UTC+1 u=C5=BCytkownik sque...@gm=
ail.com=20
napisa=C5=82:
>
> (First time here, please let me know if I'm doing anything wrong!)
>
> Just a quick idea I couldn't find elsewhere with a quick search, I was=20
> wondering if it had already been proposed and/or rejected:
>
> Would it be possible and useful to allow variable declarations inside a=
=20
> test preceding a block, and make these variables visible inside the=20
> remainder of the test and the block?
> (The "remainder of the test" part might be going too far?)
> The goal is to avoid polluting a block with variables that are really onl=
y=20
> needed inside an inner block.
>
> E.g.:
> if ((auto total < (auto max =3D getMax()) - (auto buffer =3D max / 3)) > =
1) {
>     // 'total', 'max' and 'buffer' are visible in this block and=20
> destructed at the end.
> }
>
> while (nullptr !=3D (void* buffer =3D malloc(8))) { foo(buffer); }
>
> for (int i =3D 0; i < (int end =3D 10); ++i) { cout << end - i; }
>
> switch (char c =3D getchar()) { case '\0': break; default: cout << c; }
>
> auto f =3D (P* p =3D maybeP()) ? p->foo() : 0; // Too far again?
>
> Any pointers/suggestions/criticisms welcome.
> I'd be happy to work on it further if there's any interest.
>
=20
Note that some of the above constructs are already valid in C++.

while (void* buffer =3D malloc(8)) //
  foo(buffer);                   // valid C++

for (int i =3D 0, end =3D 10; i < end; ++i) // different than your example
{ cout << end - i; }                    // but similar functionality

switch (char c =3D getchar())  // valid C++
{=20
case '\0': break;=20
default: cout << c;
}

for (iter.init(); int* i =3D iter.next();) // valid C++
  use(*i);

Your proposal offers only a bit more. The question is, whether the added=20
value counterweights the costs of standardization effort, complicating the=
=20
language, more rules for programmers to learn, compiler updates, etc. My=20
personal answer (based on feelings and intuition only) is that it is not=20
worth it.

Regards,
&rzej

--=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_111_323604260.1417595844597
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>W dniu =C5=9Broda, 3 grudnia 2014 05:21:27 UTC+1 u=
=C5=BCytkownik sque...@gmail.com napisa=C5=82:<blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;"><div dir=3D"ltr">(First time here, please let me know if I'=
m doing anything wrong!)<br><br>Just a quick idea I couldn't find elsewhere=
 with a quick search, I was wondering if it had already been proposed and/o=
r rejected:<br><br>Would it be possible and useful to allow variable declar=
ations inside a test preceding a block, and make these variables visible in=
side the remainder of the test and the block?<br>(The "remainder of the tes=
t" part might be going too far?)<br>The goal is to avoid polluting a block =
with variables that are really only needed inside an inner block.<br><br>E.=
g.:<br><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187=
,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><code><=
div><span style=3D"color:#008">if</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">((</span><span style=3D"color:#008">auto</span><=
span style=3D"color:#000"> total </span><span style=3D"color:#660">&lt;</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">(</span><s=
pan style=3D"color:#008">auto</span><span style=3D"color:#000"> max </span>=
<span style=3D"color:#660">=3D</span><span style=3D"color:#000"> getMax</sp=
an><span style=3D"color:#660">())</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">-</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#660">(</span><span style=3D"color:#008">auto</span><span s=
tyle=3D"color:#000"> buffer </span><span style=3D"color:#660">=3D</span><sp=
an style=3D"color:#000"> max </span><span style=3D"color:#660">/</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#066">3</span><span sty=
le=3D"color:#660">))</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">1</span><span style=3D"color:#660">)</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#800">// 'total', 'max'=
 and 'buffer' are visible in this block and destructed at the end.</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#660">}</span><spa=
n style=3D"color:#000"><br><br></span><span style=3D"color:#008">while</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">(</span><sp=
an style=3D"color:#008">nullptr</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">!=3D</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#008">void</span><span =
style=3D"color:#660">*</span><span style=3D"color:#000"> buffer </span><spa=
n style=3D"color:#660">=3D</span><span style=3D"color:#000"> malloc</span><=
span style=3D"color:#660">(</span><span style=3D"color:#066">8</span><span =
style=3D"color:#660">)))</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">{</span><span style=3D"color:#000"> foo</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">buffer</span><span style=
=3D"color:#660">);</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">}</span><span style=3D"color:#000"><br><br></span><span style=
=3D"color:#008">for</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">(</span><span style=3D"color:#008">int</span><span style=3D"co=
lor:#000"> i </span><span style=3D"color:#660">=3D</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#066">0</span><span style=3D"color:#6=
60">;</span><span style=3D"color:#000"> i </span><span style=3D"color:#660"=
>&lt;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">(=
</span><span style=3D"color:#008">int</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#008">end</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#066">10</span><span style=3D"color:#660">);</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#660">++</span><span sty=
le=3D"color:#000">i</span><span style=3D"color:#660">)</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"colo=
r:#000"> cout </span><span style=3D"color:#660">&lt;&lt;</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">end</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">-</span><span style=3D"colo=
r:#000"> i</span><span style=3D"color:#660">;</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><=
br><br></span><span style=3D"color:#008">switch</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">(</span><span style=3D"color:#008"=
>char</span><span style=3D"color:#000"> c </span><span style=3D"color:#660"=
>=3D</span><span style=3D"color:#000"> getchar</span><span style=3D"color:#=
660">())</span><span style=3D"color:#000"> </span><span style=3D"color:#660=
">{</span><span style=3D"color:#000"> </span><span style=3D"color:#008">cas=
e</span><span style=3D"color:#000"> </span><span style=3D"color:#080">'\0'<=
/span><span style=3D"color:#660">:</span><span style=3D"color:#000"> </span=
><span style=3D"color:#008">break</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#008">default</span=
><span style=3D"color:#660">:</span><span style=3D"color:#000"> cout </span=
><span style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> c</s=
pan><span style=3D"color:#660">;</span><span style=3D"color:#000"> </span><=
span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span=
><span style=3D"color:#008">auto</span><span style=3D"color:#000"> f </span=
><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#000">P</span><span s=
tyle=3D"color:#660">*</span><span style=3D"color:#000"> p </span><span styl=
e=3D"color:#660">=3D</span><span style=3D"color:#000"> maybeP</span><span s=
tyle=3D"color:#660">())</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#660">?</span><span style=3D"color:#000"> p</span><span style=3D=
"color:#660">-&gt;</span><span style=3D"color:#000">foo</span><span style=
=3D"color:#660">()</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color=
:#066">0</span><span style=3D"color:#660">;</span><span style=3D"color:#000=
"> </span><span style=3D"color:#800">// Too far again?</span><span style=3D=
"color:#000"><br></span></div></code></div><br>Any pointers/suggestions/<wb=
r>criticisms welcome.<br>I'd be happy to work on it further if there's any =
interest.<br></div></blockquote><div>&nbsp;</div><div>Note that some of the=
 above constructs are already valid in C++.<br><code><span style=3D"color:#=
000"><br></span><div class=3D"prettyprint" style=3D"background-color: rgb(2=
50, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; borde=
r-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div clas=
s=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">while</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> buffer </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> malloc</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"=
styled-by-prettify">8</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">))</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; foo=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">buffer</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// valid C++</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">for</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">i=
nt</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> i </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">end</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #066;" class=3D"styled-by-prettify">10</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> i </span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">end</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">++</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">i</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">// different than your example</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"> cout </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">end</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">-</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> i</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color: #800;" c=
lass=3D"styled-by-prettify">// but similar functionality</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">switch</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">char</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> c </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> getchar</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">())</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nb=
sp;</span><span style=3D"color: #800;" class=3D"styled-by-prettify">// vali=
d C++</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
/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 st=
yle=3D"color: #008;" class=3D"styled-by-prettify">case</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
080;" 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"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">break</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <b=
r></span><span style=3D"color: #008;" class=3D"styled-by-prettify">default<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> cout </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> c</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">for</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">iter</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">init</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> i </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> i=
ter</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">next</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">();)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">// valid C++</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">use</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(*</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">i</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span></div></code></div><span style=3D"color:#000"><br></spa=
n></code>Your proposal offers only a bit more. The question is, whether the=
 added value counterweights the costs of standardization effort, complicati=
ng the language, more rules for programmers to learn, compiler updates, etc=
.. My personal answer (based on feelings and intuition only) is that it is n=
ot worth it.<br><br>Regards,<br>&amp;rzej<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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
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_111_323604260.1417595844597--
------=_Part_110_1830880989.1417595844597--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 03 Dec 2014 23:15:52 +0100
Raw View
This is a multi-part message in MIME format.
--------------030606050702040807050602
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 03/12/14 05:21, squelart@gmail.com a =C3=A9crit :
> (First time here, please let me know if I'm doing anything wrong!)
>
> Just a quick idea I couldn't find elsewhere with a quick search, I was=20
> wondering if it had already been proposed and/or rejected:
>
> Would it be possible and useful to allow variable declarations inside=20
> a test preceding a block, and make these variables visible inside the=20
> remainder of the test and the block?
> (The "remainder of the test" part might be going too far?)
> The goal is to avoid polluting a block with variables that are really=20
> only needed inside an inner block.
>
> E.g.:
> |
> if((autototal <(automax =3DgetMax())-(autobuffer =3Dmax /3))>1){
> // 'total', 'max' and 'buffer' are visible in this block and=20
> destructed at the end.
> }
>
> while(nullptr!=3D(void*buffer =3Dmalloc(8))){foo(buffer);}
>
> for(inti =3D0;i <(intend=3D10);++i){cout <<end-i;}
>
> switch(charc =3Dgetchar()){case'\0':break;default:cout <<c;}
>
> autof =3D(P*p =3DmaybeP())?p->foo():0;// Too far again?
> |
>
> Any pointers/suggestions/criticisms welcome.
> I'd be happy to work on it further if there's any interest.
>
Hi,

I guess you meant

|if((autototal =3D(automax =3DgetMax())-(autobuffer =3Dmax /3))>1){
// 'total', 'max' and 'buffer' are visible in this block and destructed=20
at the end.
}
|
This implies an order of declarations/definition while the order of=20
evaluation of the parameters of an expression is undefined. This could=20
change if [1] is accepted.

Couldn't you use already the comma operator that would avoid the=20
parenthesis and make the declaration more visible.

|  if(|||automax =3DgetMax(), |||||autobuffer =3Dmax /3,| |autototal =3Dmax=
=20
-buffer>1){
// 'total', 'max' and 'buffer' are visible in this block and destructed=20
at the end.
   }

|For the particular case
|
autof =3D(P*p =3DmaybeP())?p->foo():0;// Too far again?

a monadic function would help
|
||  autof =3Deval_or(maybeP(), [](auto&& p) {p.foo()}, 0);
|
|Vicente

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4228.pdf

--=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/.

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

<html>
  <head>
    <meta content=3D"text/html; charset=3DUTF-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">Le 03/12/14 05:21, <a
        class=3D"moz-txt-link-abbreviated"
        href=3D"mailto:squelart@gmail.com">squelart@gmail.com</a> a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote
      cite=3D"mid:ba7d4c88-df31-474a-8216-60772e2e3405@isocpp.org"
      type=3D"cite">
      <div dir=3D"ltr">(First time here, please let me know if I'm doing
        anything wrong!)<br>
        <br>
        Just a quick idea I couldn't find elsewhere with a quick search,
        I was wondering if it had already been proposed and/or rejected:<br=
>
        <br>
        Would it be possible and useful to allow variable declarations
        inside a test preceding a block, and make these variables
        visible inside the remainder of the test and the block?<br>
        (The "remainder of the test" part might be going too far?)<br>
        The goal is to avoid polluting a block with variables that are
        really only needed inside an inner block.<br>
        <br>
        E.g.:<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"subprettyprint"><span style=3D"color: #008;"
                class=3D"styled-by-prettify">if</span><span style=3D"color:
                #000;" class=3D"styled-by-prettify"> </span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">((</spa=
n><span
                style=3D"color: #008;" class=3D"styled-by-prettify">auto</s=
pan><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> total =
</span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</s=
pan><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">auto</s=
pan><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> max </=
span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> getMax=
</span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">())</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">-</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">auto</s=
pan><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> buffer
              </span><span style=3D"color: #660;"
                class=3D"styled-by-prettify">=3D</span><span style=3D"color=
:
                #000;" class=3D"styled-by-prettify"> max </span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">/</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #066;" class=3D"styled-by-prettify">3</span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">))</spa=
n><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</s=
pan><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #066;" class=3D"styled-by-prettify">1</span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">)</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"><br>
                =C2=A0 =C2=A0 </span><span style=3D"color: #800;"
                class=3D"styled-by-prettify">// 'total', 'max' and
                'buffer' are visible in this block and destructed at the
                end.</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>
                <br>
              </span><span style=3D"color: #008;"
                class=3D"styled-by-prettify">while</span><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">nullptr=
</span><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">!=3D</s=
pan><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">void</s=
pan><span
                style=3D"color: #660;" class=3D"styled-by-prettify">*</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> buffer
              </span><span style=3D"color: #660;"
                class=3D"styled-by-prettify">=3D</span><span style=3D"color=
:
                #000;" class=3D"styled-by-prettify"> malloc</span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #066;" class=3D"styled-by-prettify">8</span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">)))</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> foo</s=
pan><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify">buffer<=
/span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">);</spa=
n><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">}</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"><br>
                <br>
              </span><span style=3D"color: #008;"
                class=3D"styled-by-prettify">for</span><span style=3D"color=
:
                #000;" class=3D"styled-by-prettify"> </span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">int</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> i </sp=
an><span
                style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #066;" class=3D"styled-by-prettify">0</span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> i </sp=
an><span
                style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</s=
pan><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">int</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">end</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #066;" class=3D"styled-by-prettify">10</spa=
n><span
                style=3D"color: #660;" class=3D"styled-by-prettify">);</spa=
n><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">++</spa=
n><span
                style=3D"color: #000;" class=3D"styled-by-prettify">i</span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">)</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> cout <=
/span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt=
;</span><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">end</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">-</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> i</spa=
n><span
                style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">}</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"><br>
                <br>
              </span><span style=3D"color: #008;"
                class=3D"styled-by-prettify">switch</span><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">char</s=
pan><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> c </sp=
an><span
                style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> getcha=
r</span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">())</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">case</s=
pan><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #080;" class=3D"styled-by-prettify">'\0'</s=
pan><span
                style=3D"color: #660;" class=3D"styled-by-prettify">:</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">break</=
span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #008;" class=3D"styled-by-prettify">default=
</span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">:</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> cout <=
/span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt=
;</span><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> c</spa=
n><span
                style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">}</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"><br>
                <br>
              </span><span style=3D"color: #008;"
                class=3D"styled-by-prettify">auto</span><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> f </sp=
an><span
                style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify">P</span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">*</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> p </sp=
an><span
                style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> maybeP=
</span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">())</sp=
an><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">?</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> p</spa=
n><span
                style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;</=
span><span
                style=3D"color: #000;" class=3D"styled-by-prettify">foo</sp=
an><span
                style=3D"color: #660;" class=3D"styled-by-prettify">()</spa=
n><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">:</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #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"> </span=
><span
                style=3D"color: #800;" class=3D"styled-by-prettify">// Too
                far again?</span><span style=3D"color: #000;"
                class=3D"styled-by-prettify"><br>
              </span></div>
          </code></div>
        <br>
        Any pointers/suggestions/criticisms welcome.<br>
        I'd be happy to work on it further if there's any interest.<br>
        <br>
      </div>
    </blockquote>
    Hi,<br>
    <br>
    I guess you meant <br>
    <br>
    <code class=3D"prettyprint"><span style=3D"color: #008;"
        class=3D"styled-by-prettify">if</span><span style=3D"color: #000;"
        class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"
        class=3D"styled-by-prettify">((</span><span style=3D"color: #008;"
        class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;=
"
        class=3D"styled-by-prettify"> total </span><span style=3D"color:
        #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color:
        #000;" class=3D"styled-by-prettify"> </span><span style=3D"color:
        #660;" class=3D"styled-by-prettify">(</span><span style=3D"color:
        #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color=
:
        #000;" class=3D"styled-by-prettify"> max </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> getMax</span><=
span
        style=3D"color: #660;" class=3D"styled-by-prettify">())</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">-</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span
        style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><spa=
n
        style=3D"color: #000;" class=3D"styled-by-prettify"> buffer </span>=
<span
        style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> max </span><sp=
an
        style=3D"color: #660;" class=3D"styled-by-prettify">/</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #066;" class=3D"styled-by-prettify">3</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">))</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><spa=
n
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #066;" class=3D"styled-by-prettify">1</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"><br>
        =C2=A0 =C2=A0 </span><span style=3D"color: #800;"
        class=3D"styled-by-prettify">// 'total', 'max' and 'buffer' are
        visible in this block and destructed at the end.</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"><br>
      </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></code><br>
    This implies an order of declarations/definition while the order of
    evaluation of the parameters of an expression is undefined. This
    could change if [1] is accepted.<br>
    <br>
    Couldn't you use already the comma operator that would avoid the
    parenthesis and make the declaration more visible.<br>
    <br>
    <code class=3D"prettyprint"><span style=3D"color: #008;"
        class=3D"styled-by-prettify">=C2=A0 if</span><span style=3D"color: =
#000;"
        class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"
        class=3D"styled-by-prettify">(</span></code><code
      class=3D"prettyprint"><span style=3D"color: #660;"
        class=3D"styled-by-prettify"><code class=3D"prettyprint"><span
            style=3D"color: #660;" class=3D"styled-by-prettify"></span><spa=
n
            style=3D"color: #008;" class=3D"styled-by-prettify">auto</span>=
<span
            style=3D"color: #000;" class=3D"styled-by-prettify"> max </span=
><span
            style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span
            style=3D"color: #000;" class=3D"styled-by-prettify"> getMax</sp=
an><span
            style=3D"color: #660;" class=3D"styled-by-prettify">(), </span>=
</code></span></code><code
      class=3D"prettyprint"><span style=3D"color: #660;"
        class=3D"styled-by-prettify"><code class=3D"prettyprint"><span
            style=3D"color: #660;" class=3D"styled-by-prettify"><code
              class=3D"prettyprint"><span style=3D"color: #660;"
                class=3D"styled-by-prettify"></span><span style=3D"color:
                #008;" class=3D"styled-by-prettify">auto</span><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> buffer
              </span><span style=3D"color: #660;"
                class=3D"styled-by-prettify">=3D</span><span style=3D"color=
:
                #000;" class=3D"styled-by-prettify"> max </span><span
                style=3D"color: #660;" class=3D"styled-by-prettify">/</span=
><span
                style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
                style=3D"color: #066;" class=3D"styled-by-prettify">3</span=
><span
                style=3D"color: #660;" class=3D"styled-by-prettify">,</span=
></code>
          </span></code></span><span style=3D"color: #008;"
        class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;=
"
        class=3D"styled-by-prettify"> total </span><span style=3D"color:
        #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color:
        #000;" class=3D"styled-by-prettify"> </span><span style=3D"color:
        #000;" class=3D"styled-by-prettify">max=C2=A0</span><span style=3D"=
color:
        #000;" class=3D"styled-by-prettify"></span><span style=3D"color:
        #660;" class=3D"styled-by-prettify">-</span><span style=3D"color:
        #000;" class=3D"styled-by-prettify"> </span><span style=3D"color:
        #000;" class=3D"styled-by-prettify">buffer</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify"></span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><spa=
n
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #066;" class=3D"styled-by-prettify">1</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"><br>
        =C2=A0 =C2=A0 </span><span style=3D"color: #800;"
        class=3D"styled-by-prettify">// 'total', 'max' and 'buffer' are
        visible in this block and destructed at the end.</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"><br>
      </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=C2=
=A0 }</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"><br>
        <br>
      </span></code>For the particular case<br>
    <code class=3D"prettyprint"><span style=3D"color: #000;"
        class=3D"styled-by-prettify"><br>
      </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=C2=
=A0
        auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">
        f </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify">P</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> p </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> maybeP</span><=
span
        style=3D"color: #660;" class=3D"styled-by-prettify">())</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">?</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> p</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;</span><sp=
an
        style=3D"color: #000;" class=3D"styled-by-prettify">foo</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
        style=3D"color: #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"> </span><span
        style=3D"color: #800;" class=3D"styled-by-prettify">// Too far
        again?</span><span style=3D"color: #000;"
        class=3D"styled-by-prettify"><br>
        <br>
        a monadic function would help<br>
      </span></code><br>
    <code class=3D"prettyprint"><span style=3D"color: #000;"
        class=3D"styled-by-prettify"><code class=3D"prettyprint"><span
            style=3D"color: #008;" class=3D"styled-by-prettify">=C2=A0 auto=
</span><span
            style=3D"color: #000;" class=3D"styled-by-prettify"> f </span><=
span
            style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span
            style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an
            style=3D"color: #660;" class=3D"styled-by-prettify">eval_or(</s=
pan><span
            style=3D"color: #000;" class=3D"styled-by-prettify">maybeP</spa=
n><span
            style=3D"color: #660;" class=3D"styled-by-prettify">(),
            [](auto&amp;&amp; p) {</span><span style=3D"color: #000;"
            class=3D"styled-by-prettify">p.</span><span style=3D"color:
            #660;" class=3D"styled-by-prettify"></span><span style=3D"color=
:
            #000;" class=3D"styled-by-prettify">foo</span><span
            style=3D"color: #660;" class=3D"styled-by-prettify">()}, 0)</sp=
an><span
            style=3D"color: #660;" class=3D"styled-by-prettify">;</span><sp=
an
            style=3D"color: #000;" class=3D"styled-by-prettify"><br>
          </span></code><br>
      </span></code>Vicente<br>
    <br>
    [1] <a class=3D"moz-txt-link-freetext"
      href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4228=
..pdf">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4228.pdf</a>=
<br>
    <br>
  </body>
</html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
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 />

--------------030606050702040807050602--

.


Author: squelart@gmail.com
Date: Wed, 3 Dec 2014 23:09:37 -0800 (PST)
Raw View
------=_Part_410_78606994.1417676977070
Content-Type: multipart/alternative;
 boundary="----=_Part_411_445305253.1417676977070"

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

On Wednesday, December 3, 2014 7:37:24 PM UTC+11, Andrzej Krzemie=C5=84ski =
wrote:
>
> W dniu =C5=9Broda, 3 grudnia 2014 05:21:27 UTC+1 u=C5=BCytkownik sque...@=
gmail.com=20
> napisa=C5=82:
>>
>> (First time here, please let me know if I'm doing anything wrong!)
>>
>> Just a quick idea I couldn't find elsewhere with a quick search, I was=
=20
>> wondering if it had already been proposed and/or rejected:
>>
>> Would it be possible and useful to allow variable declarations inside a=
=20
>> test preceding a block, and make these variables visible inside the=20
>> remainder of the test and the block?
>> (The "remainder of the test" part might be going too far?)
>> The goal is to avoid polluting a block with variables that are really=20
>> only needed inside an inner block.
>>
>> E.g.:
>> if ((auto total < (auto max =3D getMax()) - (auto buffer =3D max / 3)) >=
 1) {
>>     // 'total', 'max' and 'buffer' are visible in this block and=20
>> destructed at the end.
>> }
>>
>> while (nullptr !=3D (void* buffer =3D malloc(8))) { foo(buffer); }
>>
>> for (int i =3D 0; i < (int end =3D 10); ++i) { cout << end - i; }
>>
>> switch (char c =3D getchar()) { case '\0': break; default: cout << c; }
>>
>> auto f =3D (P* p =3D maybeP()) ? p->foo() : 0; // Too far again?
>>
>> Any pointers/suggestions/criticisms welcome.
>> I'd be happy to work on it further if there's any interest.
>>
> =20
> Note that some of the above constructs are already valid in C++.
>
> while (void* buffer =3D malloc(8)) //
>   foo(buffer);                   // valid C++
>
> for (int i =3D 0, end =3D 10; i < end; ++i) // different than your exampl=
e
> { cout << end - i; }                    // but similar functionality
>
> switch (char c =3D getchar())  // valid C++
> {=20
> case '\0': break;=20
> default: cout << c;
> }
>
> for (iter.init(); int* i =3D iter.next();) // valid C++
>   use(*i);
>
> Your proposal offers only a bit more. The question is, whether the added=
=20
> value counterweights the costs of standardization effort, complicating th=
e=20
> language, more rules for programmers to learn, compiler updates, etc. My=
=20
> personal answer (based on feelings and intuition only) is that it is not=
=20
> worth it.
>
> Regards,
> &rzej
>

Thanks for your help, I didn't know about some of these. Always learning!

I knew about "while (void* p =3D ...)", but it means the variable can only =
be=20
tested for "falsiness", you can't have a test that declares a variable and=
=20
compares it to an arbitrary non-false value.

But as you say, it's "only a bit more", so it's probably not worth the huge=
=20
effort to change the language just for that...

Cheers,
Gerald

--=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_411_445305253.1417676977070
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, December 3, 2014 7:37:24 PM UTC+11, Andrzej =
Krzemie=C5=84ski wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div di=
r=3D"ltr">W dniu =C5=9Broda, 3 grudnia 2014 05:21:27 UTC+1 u=C5=BCytkownik =
<a>sque...@gmail.com</a> napisa=C5=82:<blockquote class=3D"gmail_quote" sty=
le=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr">(First time here, please let me know if I'm doing anyth=
ing wrong!)<br><br>Just a quick idea I couldn't find elsewhere with a quick=
 search, I was wondering if it had already been proposed and/or rejected:<b=
r><br>Would it be possible and useful to allow variable declarations inside=
 a test preceding a block, and make these variables visible inside the rema=
inder of the test and the block?<br>(The "remainder of the test" part might=
 be going too far?)<br>The goal is to avoid polluting a block with variable=
s that are really only needed inside an inner block.<br><br>E.g.:<br><div s=
tyle=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);bor=
der-style:solid;border-width:1px;word-wrap:break-word"><code><div><span sty=
le=3D"color:#008">if</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">((</span><span style=3D"color:#008">auto</span><span style=
=3D"color:#000"> total </span><span style=3D"color:#660">&lt;</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">(</span><span style=
=3D"color:#008">auto</span><span style=3D"color:#000"> max </span><span sty=
le=3D"color:#660">=3D</span><span style=3D"color:#000"> getMax</span><span =
style=3D"color:#660">())</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">-</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">(</span><span style=3D"color:#008">auto</span><span style=3D"c=
olor:#000"> buffer </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> max </span><span style=3D"color:#660">/</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">))</span><span style=3D"color:#000"> </span><span style=3D"color=
:#660">&gt;</span><span style=3D"color:#000"> </span><span style=3D"color:#=
066">1</span><span style=3D"color:#660">)</span><span style=3D"color:#000">=
 </span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>&=
nbsp; &nbsp; </span><span style=3D"color:#800">// 'total', 'max' and 'buffe=
r' are visible in this block and destructed at the end.</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br><br></span><span style=3D"color:#008">while</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#008">nullptr</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">!=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">(</span><span style=3D"color:#008">void</span><span style=
=3D"color:#660">*</span><span style=3D"color:#000"> buffer </span><span sty=
le=3D"color:#660">=3D</span><span style=3D"color:#000"> malloc</span><span =
style=3D"color:#660">(</span><span style=3D"color:#066">8</span><span style=
=3D"color:#660">)))</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">{</span><span style=3D"color:#000"> foo</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">buffer</span><span style=3D"c=
olor:#660">);</span><span style=3D"color:#000"> </span><span style=3D"color=
:#660">}</span><span style=3D"color:#000"><br><br></span><span style=3D"col=
or:#008">for</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660">(</span><span style=3D"color:#008">int</span><span style=3D"color:#00=
0"> i </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000=
"> </span><span style=3D"color:#066">0</span><span style=3D"color:#660">;</=
span><span style=3D"color:#000"> i </span><span style=3D"color:#660">&lt;</=
span><span style=3D"color:#000"> </span><span style=3D"color:#660">(</span>=
<span style=3D"color:#008">int</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">end</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#066">10</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">++</span><span style=3D"=
color:#000">i</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000=
"> cout </span><span style=3D"color:#660">&lt;&lt;</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">end</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">-</span><span style=3D"color:#000"=
> i</span><span style=3D"color:#660">;</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br>=
</span><span style=3D"color:#008">switch</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">(</span><span style=3D"color:#008">char</=
span><span style=3D"color:#000"> c </span><span style=3D"color:#660">=3D</s=
pan><span style=3D"color:#000"> getchar</span><span style=3D"color:#660">()=
)</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#008">case</span=
><span style=3D"color:#000"> </span><span style=3D"color:#080">'\0'</span><=
span style=3D"color:#660">:</span><span style=3D"color:#000"> </span><span =
style=3D"color:#008">break</span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#008">default</span><span =
style=3D"color:#660">:</span><span style=3D"color:#000"> cout </span><span =
style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> c</span><sp=
an style=3D"color:#660">;</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><span =
style=3D"color:#008">auto</span><span style=3D"color:#000"> f </span><span =
style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#000">P</span><span style=3D=
"color:#660">*</span><span style=3D"color:#000"> p </span><span style=3D"co=
lor:#660">=3D</span><span style=3D"color:#000"> maybeP</span><span style=3D=
"color:#660">())</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#660">?</span><span style=3D"color:#000"> p</span><span style=3D"color:=
#660">-&gt;</span><span style=3D"color:#000">foo</span><span style=3D"color=
:#660">()</span><span style=3D"color:#000"> </span><span style=3D"color:#66=
0">:</span><span style=3D"color:#000"> </span><span style=3D"color:#066">0<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"> </span=
><span style=3D"color:#800">// Too far again?</span><span style=3D"color:#0=
00"><br></span></div></code></div><br>Any pointers/suggestions/<wbr>critici=
sms welcome.<br>I'd be happy to work on it further if there's any interest.=
<br></div></blockquote><div>&nbsp;</div><div>Note that some of the above co=
nstructs are already valid in C++.<br><code><span style=3D"color:#000"><br>=
</span><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187=
,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><code><=
div><span style=3D"color:#008">while</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">(</span><span style=3D"color:#008">void</span=
><span style=3D"color:#660">*</span><span style=3D"color:#000"> buffer </sp=
an><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> malloc<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#066">8</span=
><span style=3D"color:#660">))</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#800">//</span><span style=3D"color:#000"><br>&nbsp; foo<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#000">buffer<=
/span><span style=3D"color:#660">);</span><span style=3D"color:#000"> &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span styl=
e=3D"color:#800">// valid C++</span><span style=3D"color:#000"><br><br></sp=
an><span style=3D"color:#008">for</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">(</span><span style=3D"color:#008">int</span><sp=
an style=3D"color:#000"> i </span><span style=3D"color:#660">=3D</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#066">0</span><span sty=
le=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D=
"color:#008">end</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D"color=
:#066">10</span><span style=3D"color:#660">;</span><span style=3D"color:#00=
0"> i </span><span style=3D"color:#660">&lt;</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">end</span><span style=3D"color:#660">=
;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">++</s=
pan><span style=3D"color:#000">i</span><span style=3D"color:#660">)</span><=
span style=3D"color:#000"> </span><span style=3D"color:#800">// different t=
han your example</span><span style=3D"color:#000"><br></span><span style=3D=
"color:#660">{</span><span style=3D"color:#000"> cout </span><span style=3D=
"color:#660">&lt;&lt;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">end</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">-</span><span style=3D"color:#000"> i</span><span style=3D"col=
or:#660">;</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color:#800">// but =
similar functionality</span><span style=3D"color:#000"><br><br></span><span=
 style=3D"color:#008">switch</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#660">(</span><span style=3D"color:#008">char</span><span s=
tyle=3D"color:#000"> c </span><span style=3D"color:#660">=3D</span><span st=
yle=3D"color:#000"> getchar</span><span style=3D"color:#660">())</span><spa=
n style=3D"color:#000"> &nbsp;</span><span style=3D"color:#800">// valid C+=
+</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">{<=
/span><span style=3D"color:#000"> <br></span><span style=3D"color:#008">cas=
e</span><span style=3D"color:#000"> </span><span style=3D"color:#080">'\0'<=
/span><span style=3D"color:#660">:</span><span style=3D"color:#000"> </span=
><span style=3D"color:#008">break</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"> <br></span><span style=3D"color:#008">default</=
span><span style=3D"color:#660">:</span><span style=3D"color:#000"> cout </=
span><span style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> =
c</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br=
></span><span style=3D"color:#008">for</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">(</span><span style=3D"color:#000">iter</sp=
an><span style=3D"color:#660">.</span><span style=3D"color:#000">init</span=
><span style=3D"color:#660">();</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">int</span><span style=3D"color:#660">*</span><span=
 style=3D"color:#000"> i </span><span style=3D"color:#660">=3D</span><span =
style=3D"color:#000"> iter</span><span style=3D"color:#660">.</span><span s=
tyle=3D"color:#008">next</span><span style=3D"color:#660">();)</span><span =
style=3D"color:#000"> </span><span style=3D"color:#800">// valid C++</span>=
<span style=3D"color:#000"><br>&nbsp; </span><span style=3D"color:#008">use=
</span><span style=3D"color:#660">(*</span><span style=3D"color:#000">i</sp=
an><span style=3D"color:#660">);</span><span style=3D"color:#000"><br></spa=
n></div></code></div><span style=3D"color:#000"><br></span></code>Your prop=
osal offers only a bit more. The question is, whether the added value count=
erweights the costs of standardization effort, complicating the language, m=
ore rules for programmers to learn, compiler updates, etc. My personal answ=
er (based on feelings and intuition only) is that it is not worth it.<br><b=
r>Regards,<br>&amp;rzej<br></div></div></blockquote><div><br>Thanks for you=
r help, I didn't know about some of these. Always learning!<br><br>I knew a=
bout "while (void* p =3D ...)", but it means the variable can only be teste=
d for "falsiness", you can't have a test that declares a variable and compa=
res it to an arbitrary non-false value.<br><br>But as you say, it's "only a=
 bit more", so it's probably not worth the huge effort to change the langua=
ge just for that...<br><br>Cheers,<br>Gerald<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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
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_411_445305253.1417676977070--
------=_Part_410_78606994.1417676977070--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Thu, 04 Dec 2014 18:58:48 +0100
Raw View
This is a multi-part message in MIME format.
--------------000904090105090508000106
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 04/12/14 08:09, squelart@gmail.com a =C3=A9crit :
> On Wednesday, December 3, 2014 7:37:24 PM UTC+11, Andrzej Krzemie=C5=84sk=
i=20
> wrote:
>
>     W dniu =C5=9Broda, 3 grudnia 2014 05:21:27 UTC+1 u=C5=BCytkownik
>     sque...@gmail.com napisa=C5=82:
>
>         (First time here, please let me know if I'm doing anything wrong!=
)
>
>         Just a quick idea I couldn't find elsewhere with a quick
>         search, I was wondering if it had already been proposed and/or
>         rejected:
>
>         Would it be possible and useful to allow variable declarations
>         inside a test preceding a block, and make these variables
>         visible inside the remainder of the test and the block?
>         (The "remainder of the test" part might be going too far?)
>         The goal is to avoid polluting a block with variables that are
>         really only needed inside an inner block.
>
>         E.g.:
>         |
>         if((autototal <(automax =3DgetMax())-(autobuffer =3Dmax /3))>1){
>         // 'total', 'max' and 'buffer' are visible in this block and
>         destructed at the end.
>         }
>
>         while(nullptr!=3D(void*buffer =3Dmalloc(8))){foo(buffer);}
>
>         for(inti =3D0;i <(intend=3D10);++i){cout <<end-i;}
>
>         switch(charc =3Dgetchar()){case'\0':break;default:cout <<c;}
>
>         autof =3D(P*p =3DmaybeP())?p->foo():0;// Too far again?
>         |
>
>         Any pointers/suggestions/criticisms welcome.
>         I'd be happy to work on it further if there's any interest.
>
>     Note that some of the above constructs are already valid in C++.
>     |
>     |
>     while(void*buffer =3Dmalloc(8))//
>       foo(buffer);// valid C++
>
>     for(inti =3D0,end=3D10;i <end;++i)// different than your example
>     {cout <<end-i;}// but similar functionality
>
>     switch(charc =3Dgetchar())// valid C++
>     {
>     case'\0':break;
>     default:cout <<c;
>     }
>
>     for(iter.init();int*i =3Diter.next();)// valid C++
>     use(*i);
>     |
>
>     |Your proposal offers only a bit more. The question is, whether
>     the added value counterweights the costs of standardization
>     effort, complicating the language, more rules for programmers to
>     learn, compiler updates, etc. My personal answer (based on
>     feelings and intuition only) is that it is not worth it.
>
>     Regards,
>     &rzej
>
>
> Thanks for your help, I didn't know about some of these. Always learning!
>
> I knew about "while (void* p =3D ...)", but it means the variable can=20
> only be tested for "falsiness", you can't have a test that declares a=20
> variable and compares it to an arbitrary non-false value.
>
while ((void* p =3D ...) =3D=3D 0) ...
> But as you say, it's "only a bit more", so it's probably not worth the=20
> huge effort to change the language just for that...
>
Agreed,
Vicente

--=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/.

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

<html>
  <head>
    <meta content=3D"text/html; charset=3DUTF-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">Le 04/12/14 08:09, <a class=3D"moz-txt-l=
ink-abbreviated" href=3D"mailto:squelart@gmail.com">squelart@gmail.com</a> =
a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote
      cite=3D"mid:1b00c799-b47e-48b7-8717-9953b1845cca@isocpp.org"
      type=3D"cite">
      <div dir=3D"ltr">On Wednesday, December 3, 2014 7:37:24 PM UTC+11,
        Andrzej Krzemie=C5=84ski wrote:
        <blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:
          0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
          <div dir=3D"ltr">W dniu =C5=9Broda, 3 grudnia 2014 05:21:27 UTC+1
            u=C5=BCytkownik <a moz-do-not-send=3D"true">sque...@gmail.com</=
a>
            napisa=C5=82:
            <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">(First time here, please let me know if I'm
                doing anything wrong!)<br>
                <br>
                Just a quick idea I couldn't find elsewhere with a quick
                search, I was wondering if it had already been proposed
                and/or rejected:<br>
                <br>
                Would it be possible and useful to allow variable
                declarations inside a test preceding a block, and make
                these variables visible inside the remainder of the test
                and the block?<br>
                (The "remainder of the test" part might be going too
                far?)<br>
                The goal is to avoid polluting a block with variables
                that are really only needed inside an inner block.<br>
                <br>
                E.g.:<br>
                <div
style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);bo=
rder-style:solid;border-width:1px;word-wrap:break-word"><code>
                    <div><span style=3D"color:#008">if</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">((</span><span
                        style=3D"color:#008">auto</span><span
                        style=3D"color:#000"> total </span><span
                        style=3D"color:#660">&lt;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">auto</span><span
                        style=3D"color:#000"> max </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> getMax</span><span
                        style=3D"color:#660">())</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">-</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">auto</span><span
                        style=3D"color:#000"> buffer </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> max </span><span
                        style=3D"color:#660">/</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#066">3</span><span
                        style=3D"color:#660">))</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">&gt;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#066">1</span><span
                        style=3D"color:#660">)</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">{</span><span
                        style=3D"color:#000"><br>
                        =C2=A0 =C2=A0 </span><span style=3D"color:#800">// =
'total',
                        'max' and 'buffer' are visible in this block and
                        destructed at the end.</span><span
                        style=3D"color:#000"><br>
                      </span><span style=3D"color:#660">}</span><span
                        style=3D"color:#000"><br>
                        <br>
                      </span><span style=3D"color:#008">while</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">nullptr</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">!=3D</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">void</span><span
                        style=3D"color:#660">*</span><span
                        style=3D"color:#000"> buffer </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> malloc</span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#066">8</span><span
                        style=3D"color:#660">)))</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">{</span><span
                        style=3D"color:#000"> foo</span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#000">buffer</span><span
                        style=3D"color:#660">);</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">}</span><span
                        style=3D"color:#000"><br>
                        <br>
                      </span><span style=3D"color:#008">for</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">int</span><span
                        style=3D"color:#000"> i </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#066">0</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"> i </span><span
                        style=3D"color:#660">&lt;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">int</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">end</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#066">10</span><span
                        style=3D"color:#660">);</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">++</span><span
                        style=3D"color:#000">i</span><span
                        style=3D"color:#660">)</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">{</span><span
                        style=3D"color:#000"> cout </span><span
                        style=3D"color:#660">&lt;&lt;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">end</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">-</span><span
                        style=3D"color:#000"> i</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">}</span><span
                        style=3D"color:#000"><br>
                        <br>
                      </span><span style=3D"color:#008">switch</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">char</span><span
                        style=3D"color:#000"> c </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> getchar</span><span
                        style=3D"color:#660">())</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">{</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">case</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#080">'\0'</span><span
                        style=3D"color:#660">:</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">break</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">default</span><span
                        style=3D"color:#660">:</span><span
                        style=3D"color:#000"> cout </span><span
                        style=3D"color:#660">&lt;&lt;</span><span
                        style=3D"color:#000"> c</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">}</span><span
                        style=3D"color:#000"><br>
                        <br>
                      </span><span style=3D"color:#008">auto</span><span
                        style=3D"color:#000"> f </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#000">P</span><span
                        style=3D"color:#660">*</span><span
                        style=3D"color:#000"> p </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> maybeP</span><span
                        style=3D"color:#660">())</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">?</span><span
                        style=3D"color:#000"> p</span><span
                        style=3D"color:#660">-&gt;</span><span
                        style=3D"color:#000">foo</span><span
                        style=3D"color:#660">()</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">:</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#066">0</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#800">// Too far again?</span><span
                        style=3D"color:#000"><br>
                      </span></div>
                  </code></div>
                <br>
                Any pointers/suggestions/<wbr>criticisms welcome.<br>
                I'd be happy to work on it further if there's any
                interest.<br>
              </div>
            </blockquote>
            <div>=C2=A0</div>
            <div>Note that some of the above constructs are already
              valid in C++.<br>
              <code><span style=3D"color:#000"><br>
                </span>
                <div
style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);bo=
rder-style:solid;border-width:1px;word-wrap:break-word"><code>
                    <div><span style=3D"color:#008">while</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">void</span><span
                        style=3D"color:#660">*</span><span
                        style=3D"color:#000"> buffer </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> malloc</span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#066">8</span><span
                        style=3D"color:#660">))</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#800">//</span><span
                        style=3D"color:#000"><br>
                        =C2=A0 foo</span><span style=3D"color:#660">(</span=
><span
                        style=3D"color:#000">buffer</span><span
                        style=3D"color:#660">);</span><span
                        style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span
                        style=3D"color:#800">// valid C++</span><span
                        style=3D"color:#000"><br>
                        <br>
                      </span><span style=3D"color:#008">for</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">int</span><span
                        style=3D"color:#000"> i </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#066">0</span><span
                        style=3D"color:#660">,</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">end</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#066">10</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"> i </span><span
                        style=3D"color:#660">&lt;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">end</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">++</span><span
                        style=3D"color:#000">i</span><span
                        style=3D"color:#660">)</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#800">// different than your
                        example</span><span style=3D"color:#000"><br>
                      </span><span style=3D"color:#660">{</span><span
                        style=3D"color:#000"> cout </span><span
                        style=3D"color:#660">&lt;&lt;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">end</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">-</span><span
                        style=3D"color:#000"> i</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">}</span><span
                        style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span
                        style=3D"color:#800">// but similar functionality</=
span><span
                        style=3D"color:#000"><br>
                        <br>
                      </span><span style=3D"color:#008">switch</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#008">char</span><span
                        style=3D"color:#000"> c </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> getchar</span><span
                        style=3D"color:#660">())</span><span
                        style=3D"color:#000"> =C2=A0</span><span
                        style=3D"color:#800">// valid C++</span><span
                        style=3D"color:#000"><br>
                      </span><span style=3D"color:#660">{</span><span
                        style=3D"color:#000"> <br>
                      </span><span style=3D"color:#008">case</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#080">'\0'</span><span
                        style=3D"color:#660">:</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">break</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"> <br>
                      </span><span style=3D"color:#008">default</span><span
                        style=3D"color:#660">:</span><span
                        style=3D"color:#000"> cout </span><span
                        style=3D"color:#660">&lt;&lt;</span><span
                        style=3D"color:#000"> c</span><span
                        style=3D"color:#660">;</span><span
                        style=3D"color:#000"><br>
                      </span><span style=3D"color:#660">}</span><span
                        style=3D"color:#000"><br>
                        <br>
                      </span><span style=3D"color:#008">for</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#660">(</span><span
                        style=3D"color:#000">iter</span><span
                        style=3D"color:#660">.</span><span
                        style=3D"color:#000">init</span><span
                        style=3D"color:#660">();</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#008">int</span><span
                        style=3D"color:#660">*</span><span
                        style=3D"color:#000"> i </span><span
                        style=3D"color:#660">=3D</span><span
                        style=3D"color:#000"> iter</span><span
                        style=3D"color:#660">.</span><span
                        style=3D"color:#008">next</span><span
                        style=3D"color:#660">();)</span><span
                        style=3D"color:#000"> </span><span
                        style=3D"color:#800">// valid C++</span><span
                        style=3D"color:#000"><br>
                        =C2=A0 </span><span style=3D"color:#008">use</span>=
<span
                        style=3D"color:#660">(*</span><span
                        style=3D"color:#000">i</span><span
                        style=3D"color:#660">);</span><span
                        style=3D"color:#000"><br>
                      </span></div>
                  </code></div>
                <span style=3D"color:#000"><br>
                </span></code>Your proposal offers only a bit more. The
              question is, whether the added value counterweights the
              costs of standardization effort, complicating the
              language, more rules for programmers to learn, compiler
              updates, etc. My personal answer (based on feelings and
              intuition only) is that it is not worth it.<br>
              <br>
              Regards,<br>
              &amp;rzej<br>
            </div>
          </div>
        </blockquote>
        <div><br>
          Thanks for your help, I didn't know about some of these.
          Always learning!<br>
          <br>
          I knew about "while (void* p =3D ...)", but it means the
          variable can only be tested for "falsiness", you can't have a
          test that declares a variable and compares it to an arbitrary
          non-false value.<br>
          <br>
        </div>
      </div>
    </blockquote>
    while ((void* p =3D ...) =3D=3D 0) ...<br>
    <blockquote
      cite=3D"mid:1b00c799-b47e-48b7-8717-9953b1845cca@isocpp.org"
      type=3D"cite">
      <div dir=3D"ltr">
        <div>But as you say, it's "only a bit more", so it's probably
          not worth the huge effort to change the language just for
          that...<br>
          <br>
        </div>
      </div>
    </blockquote>
    Agreed,<br>
    Vicente<br>
  </body>
</html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
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 />

--------------000904090105090508000106--

.


Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Thu, 04 Dec 2014 14:35:25 -0500
Raw View
On 2014-12-04 12:58, Vicente J. Botet Escriba wrote:
> while ((void* p = ...) == 0) ...

This is not valid C++, which was (as I understood it) the point of the
original suggestion.

A condition expression may have the form of EITHER an expression or an
assignment. Not both.

  // okay
  while (p == 0)

  // okay
  while (auto p = ...)

  // invalid
  while ((auto p = ...) == 0)

--
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: Edward Catmur <ed@catmur.co.uk>
Date: Thu, 4 Dec 2014 15:14:03 -0800 (PST)
Raw View
------=_Part_1396_274131156.1417734843036
Content-Type: multipart/alternative;
 boundary="----=_Part_1397_969916077.1417734843036"

------=_Part_1397_969916077.1417734843036
Content-Type: text/plain; charset=UTF-8

On Wednesday, 3 December 2014 22:15:54 UTC, Vicente J. Botet Escriba wrote:
>
>  For the particular case
>
>   auto f = (P* p = maybeP()) ? p->foo() : 0; // Too far again?
>
> a monadic function would help
>
>   auto f = eval_or(maybeP(), [](auto&& p) {p.foo()}, 0);
>

This works pretty well with Optional, and the third argument isn't
necessary:

auto optional_filter = [](auto v, auto f) { return f(v) ? make_optional(v) :
nullopt; };
if (auto f = optional_filter(maybeP(), [](auto p) { return p.foo(); })
    requiresFoo(*f);

I wouldn't be surprised to find that this is already part of the monadic
proposals for Optional.

--

---
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_1397_969916077.1417734843036
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, 3 December 2014 22:15:54 UTC, Vicente J. Bot=
et Escriba  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div>For the particular case<br></div>
    <code><span style=3D"color:#000"><br>
      </span><span style=3D"color:#008">&nbsp;
        auto</span><span style=3D"color:#000">
        f </span><span style=3D"color:#660">=3D</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">(</span><span style=3D"color:#000"=
>P</span><span style=3D"color:#660">*</span><span style=3D"color:#000"> p <=
/span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> mayb=
eP</span><span style=3D"color:#660">())</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">?</span><span style=3D"color:#000"> p</spa=
n><span style=3D"color:#660">-&gt;</span><span style=3D"color:#000">foo</sp=
an><span style=3D"color:#660">()</span><span style=3D"color:#000"> </span><=
span style=3D"color:#660">:</span><span style=3D"color:#000"> </span><span =
style=3D"color:#066">0</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"> </span><span style=3D"color:#800">// Too far
        again?</span><span style=3D"color:#000"><br>
        <br>
        a monadic function would help<br>
      </span></code><br>
    <code><span style=3D"color:#000"><code><span style=3D"color:#008">&nbsp=
; auto</span><span style=3D"color:#000"> f </span><span style=3D"color:#660=
">=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#660">e=
val_or(</span><span style=3D"color:#000">maybeP</span><span style=3D"color:=
#660">(),
            [](auto&amp;&amp; p) {</span><span style=3D"color:#000">p.</spa=
n><span style=3D"color:#660"></span><span style=3D"color:#000">foo</span><s=
pan style=3D"color:#660">()}, 0)</span><span style=3D"color:#660">;</span><=
/code></span></code></div></blockquote><div><br></div><div>This works prett=
y well with Optional,&nbsp;and the third argument isn't necessary:</div><di=
v><br></div><div class=3D"prettyprint" style=3D"background-color: rgb(250, =
250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><c=
ode class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> optional_filter </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">[](</span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> v</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> f</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> f</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">v</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">?</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> make_optional</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">v</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> nullopt</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">if</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> optional_filter<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">maybeP</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(),</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">[](</span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> p</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> p</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">foo</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">})</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>&nbsp; &nbsp; requiresFoo</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(*</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">f</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">);</span></div></code></div><div><br></div><div>I wouldn't be surpri=
sed to find that this is already part of the monadic proposals for Optional=
..</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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
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_1397_969916077.1417734843036--
------=_Part_1396_274131156.1417734843036--

.