Topic: [std-proposals] Proposal to extend range-based fo
Author: Abdulla Herzallah <abdulla.herzallah@gmail.com>
Date: Tue, 4 Jul 2017 11:20:37 -0700 (PDT)
Raw View
------=_Part_2649_806744164.1499192437683
Content-Type: multipart/alternative;
boundary="----=_Part_2650_1708111516.1499192437684"
------=_Part_2650_1708111516.1499192437684
Content-Type: text/plain; charset="UTF-8"
HI ISO C++ Standard committee,
Apology if I am not following a proper specifications draft, I hope it will
be reviewed by someone who can help in *evaluating or enhancing* this
proposal.
This proposal is to add an extension to the range-based for loop syntax
construct to allow integer-literal values for range_declaration and
range_expression , in this case at compile time the range_expression is
evaluated for the loop which will result in generated code similar to the
"normal" for statement.
The proposal suggest two extended versions of the range-based for loop to
be added as the following:
1) for( integer-literal : integer-literal )
and
2) for( init-statement : integer-literal )
The version 2) with init-statement the data type of the init-statement will
determine the integer-literal data type, which therefore *allows only
integral data types*.
The loop will execute to the number of times equal to difference between
the init-value and range-value as in the examples below:
Example (1) only integer literal:
for (1 : 10)
{
std::cout << "\n hello world";
}
Example (2) init-statement and integer literal:
for (int i = 1 : 10)
{
std::cout << "\n hello world " << i ;
}
The loop will go 10 times and is equivalent to the loop below:
for(int i = 1; i <= 10; i++)
{
std::cout << "\n hello world " << i ;
}
The break and continue statements should work as normally expected.
*The advantage of this syntax is:*
1- Clarity of intend.
2- Brevity.
3- Minimizes chances of infinite loops, or early exiting loops.
Please let me know if I need to explain this proposal with more details.
regards
Abdulla Herzallah
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/524ec202-94cf-44cf-af4b-ff1339e6f394%40isocpp.org.
------=_Part_2650_1708111516.1499192437684
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">HI ISO C++ Standard committee,<div>=C2=A0=C2=A0<div>Apolog=
y if I am not following a proper specifications draft, I hope it will be re=
viewed by someone who can help in <u>evaluating or enhancing</u> this propo=
sal.</div><div><br>This proposal is to add an extension to the<font face=3D=
"courier new, monospace"> <font color=3D"#000000">range-based=C2=A0for loop=
</font></font> syntax construct to allow<font face=3D"courier new, monospac=
e"> <font color=3D"#000000">integer-litera</font>l</font> values for=C2=A0<=
span class=3D"t-spar" style=3D"line-height: 1.1em; font-size: 12.8px;"><fon=
t face=3D"courier new, monospace" color=3D"#000000">range_declaration </fon=
t><font color=3D"#000000" face=3D"arial, sans-serif">and=C2=A0</font></span=
><font color=3D"#000000" face=3D"courier new, monospace"><span style=3D"fon=
t-size: 12.8px;">range_expression</span></font><span class=3D"t-spar" style=
=3D"line-height: 1.1em; font-size: 12.8px;"><font color=3D"#000000" face=3D=
"arial, sans-serif">=C2=A0</font></span>, in this case at compile time the=
=C2=A0<span style=3D"color: rgb(0, 0, 0); font-family: "courier new&qu=
ot;, monospace; font-size: 12.8px;">range_expression=C2=A0</span>is evaluat=
ed for the loop which will result in generated code similar to the "no=
rmal"=C2=A0<font face=3D"courier new, monospace">for</font> statement.=
</div><div>The proposal suggest two extended versions of the <font face=3D"=
courier new, monospace">range-based for loop</font> to be added as the foll=
owing:</div><div><br></div><div><font face=3D"arial, sans-serif">1)</font><=
span style=3D"font-family: "courier new", monospace;"> =C2=A0for(=
integer-literal : integer-literal )</span><br></div><div><font face=3D"ari=
al, sans-serif"><br></font></div><div><font face=3D"arial, sans-serif">and<=
/font></div><div><font face=3D"courier new, monospace"><br></font></div><di=
v><font face=3D"arial, sans-serif">2)</font><font face=3D"courier new, mono=
space"> =C2=A0for(=C2=A0init-statement=C2=A0: integer-literal </font><span =
style=3D"font-family: "courier new", monospace;">)</span><span st=
yle=3D"font-family: "courier new", monospace;"><br></span></div><=
div>=C2=A0</div><div><br></div><div>The version 2) with <font face=3D"couri=
er new, monospace">init-statement</font> the data type of the <font face=3D=
"courier new, monospace">init-statement</font> will determine the=C2=A0<spa=
n style=3D"font-family: "courier new", monospace;">integer-litera=
l</span>=C2=A0data type, which therefore <u>allows only integral data types=
</u>.</div><div><br></div><div>The loop will execute to the number of times=
equal to difference between the <font face=3D"courier new, monospace">init=
-value</font> and <font face=3D"courier new, monospace">range-value</font>=
=C2=A0 as in the =C2=A0examples below:=C2=A0</div><div><br></div><div>Examp=
le (1) only integer literal:</div><div><font face=3D"courier new, monospace=
" color=3D"#000000">for (1 : 10) <br>{</font></div><div><font face=3D"couri=
er new, monospace" color=3D"#000000">=C2=A0 =C2=A0 std::cout << "=
;\n hello world";</font></div><div><font face=3D"courier new, monospac=
e" color=3D"#000000">}</font></div><div><font face=3D"courier new, monospac=
e" color=3D"#000000"><br></font></div><div><div>Example (2) =C2=A0init-stat=
ement and integer literal:</div><div><font face=3D"courier new, monospace" =
color=3D"#000000">for (int i =3D 1 : 10)=C2=A0<br>{</font></div><div><font =
face=3D"courier new, monospace" color=3D"#000000">=C2=A0 =C2=A0 std::cout &=
lt;< "\n hello world " << i ;</font></div><div><font fac=
e=3D"courier new, monospace" color=3D"#000000">}</font></div></div><div><br=
></div><div><div>The loop will go 10 times and is equivalent to the loop be=
low:</div></div><div><br></div><div><font face=3D"courier new, monospace">f=
or(int i =3D 1; i <=3D 10; i++)</font></div><div><div><font face=3D"cour=
ier new, monospace">{</font></div><div><font face=3D"courier new, monospace=
">=C2=A0 =C2=A0 std::cout << "\n hello world " << i ;=
</font></div><div><font face=3D"courier new, monospace">}=C2=A0</font></div=
></div><div><br></div><div><br></div><div>The <font face=3D"courier new, mo=
nospace">break</font> and <font face=3D"courier new, monospace">continue</f=
ont> statements should =C2=A0work as normally expected.</div><div><br></div=
><div><br></div><div><u>The advantage of this syntax is:</u><br></div><div>=
1- Clarity of intend.</div><div>2- Brevity.</div><div>3- Minimizes chances =
of infinite loops, or early exiting loops.</div><div><br></div><div>Please =
let me know if I need to explain this proposal with more details.</div><div=
><br></div><div>regards</div><div>Abdulla Herzallah</div><div><br></div></d=
iv></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/524ec202-94cf-44cf-af4b-ff1339e6f394%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/524ec202-94cf-44cf-af4b-ff1339e6f394=
%40isocpp.org</a>.<br />
------=_Part_2650_1708111516.1499192437684--
------=_Part_2649_806744164.1499192437683--
.