Topic: Add for loop over enum. STD Proposal.


Author: Konstantin Frumkin <fro0mberg@gmail.com>
Date: Mon, 6 Mar 2017 07:22:29 -0800 (PST)
Raw View
------=_Part_1111_816371561.1488813749069
Content-Type: multipart/alternative;
 boundary="----=_Part_1112_1639866486.1488813749069"

------=_Part_1112_1639866486.1488813749069
Content-Type: text/plain; charset=UTF-8

Thousands of case where developers use enum value as an index argument and
it is highly helpful to be able to have a loop over enum list.
example:
void doSmth(Fruits t_index);

enum Fruits { Apple, Banana = 41, Orange, Kiwi };
for (Fruits fruit: Fruits::values) {
    doSmth(index);
}

The implementation of it is similar to
std::array<int, 4> fruits_values {1, 41, 42, 43}; // not human-readable

for (int fruit: fruits_values) {
    doSmth((Fruit)index);
}

Array as enum is constexpr and compile time initialized.
However the form with use of Human-readable enum is much more nice and
friendly.

Related: Let the developer to know number of items in enum at compile time. <https://groups.google.com/a/isocpp.org/forum/?utm_medium=email&utm_source=footer#%21topic/std-proposals/Ewq7HUNwdO4>
Make C++ more sweet!

--
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/89820685-1f95-455d-a587-c8495a33f9b1%40isocpp.org.

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

<div dir=3D"ltr">Thousands of case where developers use enum value as an in=
dex argument=20
and it is highly helpful to be able to have a loop over enum list.<br>examp=
le:<br><div style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: br=
eak-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"=
subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">v=
oid</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> doSmth=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">Fruits</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> t_index</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br=
><div style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187,=
 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-wo=
rd;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subpre=
ttyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">enum</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #606;" class=3D"styled-by-prettify">Fruits</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Apple</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Banana</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">41</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">Orange</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">K=
iwi</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">for</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><code class=3D"prettyprint"><span st=
yle=3D"color: #606;" class=3D"styled-by-prettify">Fruits</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"></span></code><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> fruit</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: #606;" class=
=3D"styled-by-prettify">Fruits</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">values</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 d=
oSmth</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">index</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span></div></code></div><br>Th=
e implementation of it is similar to <div style=3D"background-color: rgb(25=
0, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border=
-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">array</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">int</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: #066;" class=3D"styled-by-prettify">4</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> fruits_values </span><span style=
=3D"color: #660;" 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: #066;" class=3D"styled-by=
-prettify">41</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: #066;" class=3D"styled-by-prettify">42</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: #0=
66;" class=3D"styled-by-prettify">43</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-p=
rettify">// not human-readable</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"st=
yled-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=
">(int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><code class=3D"prettyprint"><span style=3D"color: #000;" class=3D"style=
d-by-prettify">fruit</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify"></span></code><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f=
ruits_values</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 st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 doSmth<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">((Fruit)</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">index</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">}</span></div></code></div><br>A=
rray as enum is constexpr and compile time initialized.<br>However the form=
 with use of Human-readable enum is much more nice and friendly.<code class=
=3D"prettyprint"><span style=3D"color: #660;" class=3D"styled-by-prettify">=
<br></span></code><br><pre><code>Related: <a href=3D"https://groups.google.=
com/a/isocpp.org/forum/?utm_medium=3Demail&amp;utm_source=3Dfooter#%21topic=
/std-proposals/Ewq7HUNwdO4">Let the developer to know number of items in en=
um at compile time.</a><br>Make C++ more sweet!<br></code></pre></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/89820685-1f95-455d-a587-c8495a33f9b1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/89820685-1f95-455d-a587-c8495a33f9b1=
%40isocpp.org</a>.<br />

------=_Part_1112_1639866486.1488813749069--

------=_Part_1111_816371561.1488813749069--

.


Author: Konstantin Frumkin <fro0mberg@gmail.com>
Date: Mon, 6 Mar 2017 07:31:07 -0800 (PST)
Raw View
------=_Part_1595_1366869154.1488814268028
Content-Type: multipart/alternative;
 boundary="----=_Part_1596_1350058330.1488814268028"

------=_Part_1596_1350058330.1488814268028
Content-Type: text/plain; charset=UTF-8

Fruits::values
can be also substituted with
Fruits::values()
with prototype as something like
initializer_list<Fruits> Fruits::values();

On Monday, March 6, 2017 at 6:22:29 PM UTC+3, Konstantin Frumkin wrote:
>
> Thousands of case where developers use enum value as an index argument and
> it is highly helpful to be able to have a loop over enum list.
> example:
> void doSmth(Fruits t_index);
>
> enum Fruits { Apple, Banana = 41, Orange, Kiwi };
> for (Fruits fruit: Fruits::values) {
>     doSmth(index);
> }
>
> The implementation of it is similar to
> std::array<int, 4> fruits_values {1, 41, 42, 43}; // not human-readable
>
> for (int fruit: fruits_values) {
>     doSmth((Fruit)index);
> }
>
> Array as enum is constexpr and compile time initialized.
> However the form with use of Human-readable enum is much more nice and
> friendly.
>
> Related: Let the developer to know number of items in enum at compile time. <https://groups.google.com/a/isocpp.org/forum/?utm_medium=email&utm_source=footer#%21topic/std-proposals/Ewq7HUNwdO4>
> Make C++ more sweet!
>
>

--
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/ee8b935a-06f8-4408-b30e-03d24e326c7f%40isocpp.org.

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

<div dir=3D"ltr"><div class=3D"prettyprint" style=3D"background-color: rgb(=
250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bord=
er-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">Fruits</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">values<=
/span></div></code></div><span style=3D"font-family: monospace; background-=
color: rgb(250, 250, 250); color: rgb(0, 0, 0);">can be also substituted wi=
th=C2=A0</span><div class=3D"prettyprint" style=3D"background-color: rgb(25=
0, 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: #606;" class=3D"styled-by-prettif=
y">Fruits</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:=
:</span><span style=3D"color: #000;" class=3D"styled-by-prettify">values</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span></di=
v></code></div><span style=3D"font-family: monospace; background-color: rgb=
(250, 250, 250); color: rgb(0, 0, 0);">with prototype as something like</sp=
an><div><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"sub=
prettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">init=
ializer_list</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&lt;</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Frui=
ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #606;" class=3D"styled-by-prettify">Fruits</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">values</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span></div></code></div><br>On Monday, M=
arch 6, 2017 at 6:22:29 PM UTC+3, Konstantin Frumkin wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #c=
cc solid;padding-left: 1ex;"><div dir=3D"ltr">Thousands of case where devel=
opers use enum value as an index argument=20
and it is highly helpful to be able to have a loop over enum list.<br>examp=
le:<br><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187=
,187,187);border-style:solid;border-width:1px"><code><div><span style=3D"co=
lor:#008">void</span><span style=3D"color:#000"> doSmth</span><span style=
=3D"color:#660">(</span><span style=3D"color:#606">Fruits</span><span style=
=3D"color:#000"> t_index</span><span style=3D"color:#660">);</span><span st=
yle=3D"color:#000"><br></span></div></code></div><br><div style=3D"backgrou=
nd-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;=
border-width:1px"><code><div><span style=3D"color:#008">enum</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#606">Fruits</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Apple</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#606">Banana</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#066">41</span><span style=3D"color:#660">,</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#606">Orange</span><span style=3D"color:#6=
60">,</span><span style=3D"color:#000"> </span><span style=3D"color:#606">K=
iwi</span><span style=3D"color:#000"> </span><span style=3D"color:#660">};<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#008">for<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#660">(</span=
><code><span style=3D"color:#606">Fruits</span><span style=3D"color:#660"><=
/span></code><span style=3D"color:#000"> fruit</span><span style=3D"color:#=
660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#606">=
Fruits</span><span style=3D"color:#660">::</span><span style=3D"color:#000"=
>values</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 doSmth</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">index</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#660">}</span></div></code>=
</div><br>The implementation of it is similar to <div style=3D"background-c=
olor:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;bord=
er-width:1px"><code><div><span style=3D"color:#000">std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">array</span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#008">int</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">4</span><span style=3D"color:#660">&gt;</span><span style=3D"col=
or:#000"> fruits_values </span><span style=3D"color:#660">{</span><span sty=
le=3D"color:#066">1</span><span style=3D"color:#660">,</span><span style=3D=
"color:#000"> </span><span style=3D"color:#066">41</span><span style=3D"col=
or:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">42</span><span style=3D"color:#660">,</span><span style=3D"color:#000">=
 </span><span style=3D"color:#066">43</span><span style=3D"color:#660">};</=
span><span style=3D"color:#000"> </span><span style=3D"color:#800">// not h=
uman-readable</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">(int</span><span style=3D"color:#000"> </span><code><span styl=
e=3D"color:#000">fruit</span><span style=3D"color:#660"></span></code><span=
 style=3D"color:#660">:</span><span style=3D"color:#000"> fruits_values</sp=
an><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 doSmth</span><span style=3D"color:#660">((Fruit)</span><span style=3D"c=
olor:#000">index</span><span style=3D"color:#660">);</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#660">}</span></div></code></div=
><br>Array as enum is constexpr and compile time initialized.<br>However th=
e form with use of Human-readable enum is much more nice and friendly.<code=
><span style=3D"color:#660"><br></span></code><br><pre><code>Related: <a hr=
ef=3D"https://groups.google.com/a/isocpp.org/forum/?utm_medium=3Demail&amp;=
utm_source=3Dfooter#%21topic/std-proposals/Ewq7HUNwdO4" target=3D"_blank" r=
el=3D"nofollow" onmousedown=3D"this.href=3D&#39;https://groups.google.com/a=
/isocpp.org/forum/?utm_medium\x3demail\x26utm_source\x3dfooter#%21topic/std=
-proposals/Ewq7HUNwdO4&#39;;return true;" onclick=3D"this.href=3D&#39;https=
://groups.google.com/a/isocpp.org/forum/?utm_medium\x3demail\x26utm_source\=
x3dfooter#%21topic/std-proposals/Ewq7HUNwdO4&#39;;return true;">Let the dev=
eloper to know number of items in enum at compile time.</a><br>Make C++ mor=
e sweet!<br></code></pre></div></blockquote></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ee8b935a-06f8-4408-b30e-03d24e326c7f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ee8b935a-06f8-4408-b30e-03d24e326c7f=
%40isocpp.org</a>.<br />

------=_Part_1596_1350058330.1488814268028--

------=_Part_1595_1366869154.1488814268028--

.


Author: =?UTF-8?Q?Micha=C5=82_Dominiak?= <griwes@griwes.info>
Date: Mon, 06 Mar 2017 15:33:24 +0000
Raw View
--001a114e52885434b0054a119ef6
Content-Type: text/plain; charset=UTF-8

This has the same problems as your other thread.

Also do look at currently discussed proposal for a Reflection TS. (Please
try to do research about a thing you want before mindlessly proposing a
design you've spent three minutes on - often there's someone working on a
thing for *years* who went through all the problems you're going to hit
along the way.)

On Mon, Mar 6, 2017 at 4:31 PM Konstantin Frumkin <fro0mberg@gmail.com>
wrote:

> Fruits::values
> can be also substituted with
> Fruits::values()
> with prototype as something like
> initializer_list<Fruits> Fruits::values();
>
> On Monday, March 6, 2017 at 6:22:29 PM UTC+3, Konstantin Frumkin wrote:
>
> Thousands of case where developers use enum value as an index argument and
> it is highly helpful to be able to have a loop over enum list.
> example:
> void doSmth(Fruits t_index);
>
> enum Fruits { Apple, Banana = 41, Orange, Kiwi };
> for (Fruits fruit: Fruits::values) {
>     doSmth(index);
> }
>
> The implementation of it is similar to
> std::array<int, 4> fruits_values {1, 41, 42, 43}; // not human-readable
>
> for (int fruit: fruits_values) {
>     doSmth((Fruit)index);
> }
>
> Array as enum is constexpr and compile time initialized.
> However the form with use of Human-readable enum is much more nice and
> friendly.
>
> Related: Let the developer to know number of items in enum at compile time. <https://groups.google.com/a/isocpp.org/forum/?utm_medium=email&utm_source=footer#%21topic/std-proposals/Ewq7HUNwdO4>
> Make C++ more sweet!
>
> --
> 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/ee8b935a-06f8-4408-b30e-03d24e326c7f%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ee8b935a-06f8-4408-b30e-03d24e326c7f%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>

--
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/CAPCFJdQ%2Bn8DQBmUR7BXtgCKmxuff6hoVVoT-QjGS8hpWnyituQ%40mail.gmail.com.

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

<div dir=3D"ltr">This has the same problems as your other thread.<br><br>Al=
so do look at currently discussed proposal for a Reflection TS. (Please try=
 to do research about a thing you want before mindlessly proposing a design=
 you&#39;ve spent three minutes on - often there&#39;s someone working on a=
 thing for <i>years</i>=C2=A0who went through all the problems you&#39;re g=
oing to hit along the way.)</div><br><div class=3D"gmail_quote"><div dir=3D=
"ltr">On Mon, Mar 6, 2017 at 4:31 PM Konstantin Frumkin &lt;<a href=3D"mail=
to:fro0mberg@gmail.com">fro0mberg@gmail.com</a>&gt; wrote:<br></div><blockq=
uote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc =
solid;padding-left:1ex"><div dir=3D"ltr" class=3D"gmail_msg"><div class=3D"=
m_4100285914731285510prettyprint gmail_msg" style=3D"background-color:rgb(2=
50,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1=
px;word-wrap:break-word"><code class=3D"m_4100285914731285510prettyprint gm=
ail_msg"><div class=3D"m_4100285914731285510subprettyprint gmail_msg"><span=
 style=3D"color:#606" class=3D"m_4100285914731285510styled-by-prettify gmai=
l_msg">Fruits</span><span style=3D"color:#660" class=3D"m_41002859147312855=
10styled-by-prettify gmail_msg">::</span><span style=3D"color:#000" class=
=3D"m_4100285914731285510styled-by-prettify gmail_msg">values</span></div><=
/code></div><span style=3D"font-family:monospace;background-color:rgb(250,2=
50,250);color:rgb(0,0,0)" class=3D"gmail_msg">can be also substituted with=
=C2=A0</span><div class=3D"m_4100285914731285510prettyprint gmail_msg" styl=
e=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"m_410028=
5914731285510prettyprint gmail_msg"><div class=3D"m_4100285914731285510subp=
rettyprint gmail_msg"><span style=3D"color:#606" class=3D"m_410028591473128=
5510styled-by-prettify gmail_msg">Fruits</span><span style=3D"color:#660" c=
lass=3D"m_4100285914731285510styled-by-prettify gmail_msg">::</span><span s=
tyle=3D"color:#000" class=3D"m_4100285914731285510styled-by-prettify gmail_=
msg">values</span><span style=3D"color:#660" class=3D"m_4100285914731285510=
styled-by-prettify gmail_msg">()</span></div></code></div><span style=3D"fo=
nt-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)" cla=
ss=3D"gmail_msg">with prototype as something like</span><div class=3D"gmail=
_msg"><div class=3D"m_4100285914731285510prettyprint gmail_msg" style=3D"ba=
ckground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:=
solid;border-width:1px;word-wrap:break-word"><code class=3D"m_4100285914731=
285510prettyprint gmail_msg"><div class=3D"m_4100285914731285510subprettypr=
int gmail_msg"><span style=3D"color:#000" class=3D"m_4100285914731285510sty=
led-by-prettify gmail_msg">initializer_list</span><span style=3D"color:#660=
" class=3D"m_4100285914731285510styled-by-prettify gmail_msg">&lt;</span><s=
pan style=3D"color:#606" class=3D"m_4100285914731285510styled-by-prettify g=
mail_msg">Fruits</span><span style=3D"color:#660" class=3D"m_41002859147312=
85510styled-by-prettify gmail_msg">&gt;</span><span style=3D"color:#000" cl=
ass=3D"m_4100285914731285510styled-by-prettify gmail_msg"> </span><span sty=
le=3D"color:#606" class=3D"m_4100285914731285510styled-by-prettify gmail_ms=
g">Fruits</span><span style=3D"color:#660" class=3D"m_4100285914731285510st=
yled-by-prettify gmail_msg">::</span><span style=3D"color:#000" class=3D"m_=
4100285914731285510styled-by-prettify gmail_msg">values</span><span style=
=3D"color:#660" class=3D"m_4100285914731285510styled-by-prettify gmail_msg"=
>();</span><span style=3D"color:#000" class=3D"m_4100285914731285510styled-=
by-prettify gmail_msg"><br class=3D"gmail_msg"></span></div></code></div></=
div></div><div dir=3D"ltr" class=3D"gmail_msg"><div class=3D"gmail_msg"><br=
 class=3D"gmail_msg">On Monday, March 6, 2017 at 6:22:29 PM UTC+3, Konstant=
in Frumkin wrote:<blockquote class=3D"gmail_quote gmail_msg" style=3D"margi=
n:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr" class=3D"gmail_msg">Thousands of case where developers use enum va=
lue as an index argument=20
and it is highly helpful to be able to have a loop over enum list.<br class=
=3D"gmail_msg">example:<br class=3D"gmail_msg"><div style=3D"background-col=
or:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border=
-width:1px" class=3D"gmail_msg"><code class=3D"gmail_msg"><div class=3D"gma=
il_msg"><span style=3D"color:#008" class=3D"gmail_msg">void</span><span sty=
le=3D"color:#000" class=3D"gmail_msg"> doSmth</span><span style=3D"color:#6=
60" class=3D"gmail_msg">(</span><span style=3D"color:#606" class=3D"gmail_m=
sg">Fruits</span><span style=3D"color:#000" class=3D"gmail_msg"> t_index</s=
pan><span style=3D"color:#660" class=3D"gmail_msg">);</span><span style=3D"=
color:#000" class=3D"gmail_msg"><br class=3D"gmail_msg"></span></div></code=
></div><br class=3D"gmail_msg"><div style=3D"background-color:rgb(250,250,2=
50);border-color:rgb(187,187,187);border-style:solid;border-width:1px" clas=
s=3D"gmail_msg"><code class=3D"gmail_msg"><div class=3D"gmail_msg"><span st=
yle=3D"color:#008" class=3D"gmail_msg">enum</span><span style=3D"color:#000=
" class=3D"gmail_msg"> </span><span style=3D"color:#606" class=3D"gmail_msg=
">Fruits</span><span style=3D"color:#000" class=3D"gmail_msg"> </span><span=
 style=3D"color:#660" class=3D"gmail_msg">{</span><span style=3D"color:#000=
" class=3D"gmail_msg"> </span><span style=3D"color:#606" class=3D"gmail_msg=
">Apple</span><span style=3D"color:#660" class=3D"gmail_msg">,</span><span =
style=3D"color:#000" class=3D"gmail_msg"> </span><span style=3D"color:#606"=
 class=3D"gmail_msg">Banana</span><span style=3D"color:#000" class=3D"gmail=
_msg"> </span><span style=3D"color:#660" class=3D"gmail_msg">=3D</span><spa=
n style=3D"color:#000" class=3D"gmail_msg"> </span><span style=3D"color:#06=
6" class=3D"gmail_msg">41</span><span style=3D"color:#660" class=3D"gmail_m=
sg">,</span><span style=3D"color:#000" class=3D"gmail_msg"> </span><span st=
yle=3D"color:#606" class=3D"gmail_msg">Orange</span><span style=3D"color:#6=
60" class=3D"gmail_msg">,</span><span style=3D"color:#000" class=3D"gmail_m=
sg"> </span><span style=3D"color:#606" class=3D"gmail_msg">Kiwi</span><span=
 style=3D"color:#000" class=3D"gmail_msg"> </span><span style=3D"color:#660=
" class=3D"gmail_msg">};</span><span style=3D"color:#000" class=3D"gmail_ms=
g"><br class=3D"gmail_msg"></span><span style=3D"color:#008" class=3D"gmail=
_msg">for</span><span style=3D"color:#000" class=3D"gmail_msg"> </span><spa=
n style=3D"color:#660" class=3D"gmail_msg">(</span><code class=3D"gmail_msg=
"><span style=3D"color:#606" class=3D"gmail_msg">Fruits</span><span style=
=3D"color:#660" class=3D"gmail_msg"></span></code><span style=3D"color:#000=
" class=3D"gmail_msg"> fruit</span><span style=3D"color:#660" class=3D"gmai=
l_msg">:</span><span style=3D"color:#000" class=3D"gmail_msg"> </span><span=
 style=3D"color:#606" class=3D"gmail_msg">Fruits</span><span style=3D"color=
:#660" class=3D"gmail_msg">::</span><span style=3D"color:#000" class=3D"gma=
il_msg">values</span><span style=3D"color:#660" class=3D"gmail_msg">)</span=
><span style=3D"color:#000" class=3D"gmail_msg"> </span><span style=3D"colo=
r:#660" class=3D"gmail_msg">{</span><span style=3D"color:#000" class=3D"gma=
il_msg"><br class=3D"gmail_msg">=C2=A0 =C2=A0 doSmth</span><span style=3D"c=
olor:#660" class=3D"gmail_msg">(</span><span style=3D"color:#000" class=3D"=
gmail_msg">index</span><span style=3D"color:#660" class=3D"gmail_msg">);</s=
pan><span style=3D"color:#000" class=3D"gmail_msg"><br class=3D"gmail_msg">=
</span><span style=3D"color:#660" class=3D"gmail_msg">}</span></div></code>=
</div><br class=3D"gmail_msg">The implementation of it is similar to <div s=
tyle=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);bor=
der-style:solid;border-width:1px" class=3D"gmail_msg"><code class=3D"gmail_=
msg"><div class=3D"gmail_msg"><span style=3D"color:#000" class=3D"gmail_msg=
">std</span><span style=3D"color:#660" class=3D"gmail_msg">::</span><span s=
tyle=3D"color:#000" class=3D"gmail_msg">array</span><span style=3D"color:#6=
60" class=3D"gmail_msg">&lt;</span><span style=3D"color:#008" class=3D"gmai=
l_msg">int</span><span style=3D"color:#660" class=3D"gmail_msg">,</span><sp=
an style=3D"color:#000" class=3D"gmail_msg"> </span><span style=3D"color:#0=
66" class=3D"gmail_msg">4</span><span style=3D"color:#660" class=3D"gmail_m=
sg">&gt;</span><span style=3D"color:#000" class=3D"gmail_msg"> fruits_value=
s </span><span style=3D"color:#660" class=3D"gmail_msg">{</span><span style=
=3D"color:#066" class=3D"gmail_msg">1</span><span style=3D"color:#660" clas=
s=3D"gmail_msg">,</span><span style=3D"color:#000" class=3D"gmail_msg"> </s=
pan><span style=3D"color:#066" class=3D"gmail_msg">41</span><span style=3D"=
color:#660" class=3D"gmail_msg">,</span><span style=3D"color:#000" class=3D=
"gmail_msg"> </span><span style=3D"color:#066" class=3D"gmail_msg">42</span=
><span style=3D"color:#660" class=3D"gmail_msg">,</span><span style=3D"colo=
r:#000" class=3D"gmail_msg"> </span><span style=3D"color:#066" class=3D"gma=
il_msg">43</span><span style=3D"color:#660" class=3D"gmail_msg">};</span><s=
pan style=3D"color:#000" class=3D"gmail_msg"> </span><span style=3D"color:#=
800" class=3D"gmail_msg">// not human-readable</span><span style=3D"color:#=
000" class=3D"gmail_msg"><br class=3D"gmail_msg"><br class=3D"gmail_msg"></=
span><span style=3D"color:#008" class=3D"gmail_msg">for</span><span style=
=3D"color:#000" class=3D"gmail_msg"> </span><span style=3D"color:#660" clas=
s=3D"gmail_msg">(int</span><span style=3D"color:#000" class=3D"gmail_msg"> =
</span><code class=3D"gmail_msg"><span style=3D"color:#000" class=3D"gmail_=
msg">fruit</span><span style=3D"color:#660" class=3D"gmail_msg"></span></co=
de><span style=3D"color:#660" class=3D"gmail_msg">:</span><span style=3D"co=
lor:#000" class=3D"gmail_msg"> fruits_values</span><span style=3D"color:#66=
0" class=3D"gmail_msg">)</span><span style=3D"color:#000" class=3D"gmail_ms=
g"> </span><span style=3D"color:#660" class=3D"gmail_msg">{</span><span sty=
le=3D"color:#000" class=3D"gmail_msg"><br class=3D"gmail_msg">=C2=A0 =C2=A0=
 doSmth</span><span style=3D"color:#660" class=3D"gmail_msg">((Fruit)</span=
><span style=3D"color:#000" class=3D"gmail_msg">index</span><span style=3D"=
color:#660" class=3D"gmail_msg">);</span><span style=3D"color:#000" class=
=3D"gmail_msg"><br class=3D"gmail_msg"></span><span style=3D"color:#660" cl=
ass=3D"gmail_msg">}</span></div></code></div><br class=3D"gmail_msg">Array =
as enum is constexpr and compile time initialized.<br class=3D"gmail_msg">H=
owever the form with use of Human-readable enum is much more nice and frien=
dly.<code class=3D"gmail_msg"><span style=3D"color:#660" class=3D"gmail_msg=
"><br class=3D"gmail_msg"></span></code><br class=3D"gmail_msg"><pre class=
=3D"gmail_msg"><code class=3D"gmail_msg">Related: <a href=3D"https://groups=
..google.com/a/isocpp.org/forum/?utm_medium=3Demail&amp;utm_source=3Dfooter#=
%21topic/std-proposals/Ewq7HUNwdO4" rel=3D"nofollow" class=3D"gmail_msg" ta=
rget=3D"_blank">Let the developer to know number of items in enum at compil=
e time.</a><br class=3D"gmail_msg">Make C++ more sweet!<br class=3D"gmail_m=
sg"></code></pre></div></blockquote></div></div>

<p class=3D"gmail_msg"></p>

-- <br class=3D"gmail_msg">
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br class=3D"gmail_msg=
">
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" class=3D"gm=
ail_msg" target=3D"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br cla=
ss=3D"gmail_msg">
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" class=3D"gmail_msg" target=3D"_blank">std-proposals@isocpp.org</a>.<b=
r class=3D"gmail_msg">
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ee8b935a-06f8-4408-b30e-03d24e326c7f%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" class=3D"gmail_msg=
" target=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-prop=
osals/ee8b935a-06f8-4408-b30e-03d24e326c7f%40isocpp.org</a>.<br class=3D"gm=
ail_msg">
</blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAPCFJdQ%2Bn8DQBmUR7BXtgCKmxuff6hoVVo=
T-QjGS8hpWnyituQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAPCFJdQ%2Bn8DQ=
BmUR7BXtgCKmxuff6hoVVoT-QjGS8hpWnyituQ%40mail.gmail.com</a>.<br />

--001a114e52885434b0054a119ef6--

.