Topic: std::enum
Author: Halfdan Ingvarsson <halfdan@gmail.com>
Date: Tue, 20 Jun 2017 20:34:28 -0700 (PDT)
Raw View
------=_Part_4754_1603844511.1498016068257
Content-Type: multipart/alternative;
boundary="----=_Part_4755_878829838.1498016068258"
------=_Part_4755_878829838.1498016068258
Content-Type: text/plain; charset="UTF-8"
I'd like to propose a simple, but very useful utility class for the
standard library: std::enum.
All it does is take a template parameter, which would be an enum type.
It would then allow you to access the individual elements of that enum, in
order of declaration, using a nearly identical interface as std::array<>
(i.e either through enumerators, or operator[]).
E.g:
#include <iostream>
#include <enum>
#include <algorithm>
enum Color { Red = 1, Green = 2, Blue = 23 };
int main()
{
auto e = std::enum<Color>();
for( auto v: e)
{
std::cout << "Elem: " << v << "\n";
}
std::cout << "Size: " << e.size() << "\n";
std::cout << "Largest: " << std::max_element(e.begin(), e.end()) << "\n";
return 0;
}
Output:
Elem: 1
Elem: 2
Elem: 23
Size: 3
Largest: 23
I assume that this would have to take some form of a help from the
compiler, similar to how std::underlying_type is implemented. However, this
would obviate the current set of hacks that either require macros, special
class constructions, or other inconvenient forms.
--
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/1cdd0fbf-c65d-4034-82d1-a84d4c4f6d1c%40isocpp.org.
------=_Part_4755_878829838.1498016068258
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I'd like to propose a simple, but very useful utility =
class for the standard library: std::enum. =C2=A0<div><br></div><div>All it=
does is take a template parameter, which would be an enum type.</div><div>=
<br></div><div>It would then allow you to access the individual elements of=
that enum, in order of declaration, using a nearly identical interface as =
std::array<> (i.e either through enumerators, or operator[]).</div><d=
iv><div><br></div><div>E.g:=C2=A0</div><div><br></div><div class=3D"prettyp=
rint" 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"c=
olor: #800;" class=3D"styled-by-prettify">#include</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;=
" class=3D"styled-by-prettify"><iostream></span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;=
" class=3D"styled-by-prettify">#include</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"=
styled-by-prettify"><enum></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">#include</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-pre=
ttify"><algorithm></span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br><br><br></span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">enum</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Color</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </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: #606;" class=3D"styled-by-prettify">Red</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=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-b=
y-prettify">1</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: #606;" class=3D"styled-by-prettify">Green</span><sp=
an 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"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;=
" class=3D"styled-by-prettify">2</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">Blue</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"> </span><span st=
yle=3D"color: #066;" class=3D"styled-by-prettify">23</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br><br><br></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> main</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></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: #008;" class=3D"styled-by-prettify">=
auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> e </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">enum</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">Color</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: #008;" c=
lass=3D"styled-by-prettify">for</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-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"> v<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> e</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0std</span><sp=
an 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"c=
olor: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;=
" class=3D"styled-by-prettify">"Elem: "</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
class=3D"styled-by-prettify"><<</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> v </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><<</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-=
prettify">"\n"</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 =C2=A0std</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">cout </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
<<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #080;" class=3D"styled-by-prettify">"Size:=
"</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify"><<</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> e</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">size</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"s=
tyled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-=
prettify">"\n"</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0std</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">cout </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
"><<</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"Lar=
gest: "</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"> std</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">max_element</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">e</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">begin</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(),</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> e</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">.</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-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><<</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">"\n"</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" cl=
ass=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">}</span></div></code></div><div><font face=3D"courier new, monospace"><b=
r></font></div><div><font face=3D"arial, sans-serif">Output:</font></div><d=
iv class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bor=
der-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word=
-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprin=
t"><span style=3D"color: #606;" class=3D"styled-by-prettify">Elem</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">1</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Elem</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">=
2</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">Elem</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=
: #066;" class=3D"styled-by-prettify">23</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Size</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">=
3</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">Largest</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #066;" class=3D"styled-by-prettify">23</span></div></code></div><div><fo=
nt face=3D"courier new, monospace"><br></font></div><div>I assume that this=
would have to take some form of a help from the compiler, similar to how s=
td::underlying_type is implemented. However, this would obviate the current=
set of hacks that either require macros, special class constructions, or o=
ther inconvenient forms.</div></div><div><br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1cdd0fbf-c65d-4034-82d1-a84d4c4f6d1c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1cdd0fbf-c65d-4034-82d1-a84d4c4f6d1c=
%40isocpp.org</a>.<br />
------=_Part_4755_878829838.1498016068258--
------=_Part_4754_1603844511.1498016068257--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 20 Jun 2017 21:06:49 -0700
Raw View
On Tuesday, 20 June 2017 20:34:28 PDT Halfdan Ingvarsson wrote:
> I'd like to propose a simple, but very useful utility class for the
> standard library: std::enum.
You need to find a different name. We can't have a class whose name is a
reserved keyword.
> All it does is take a template parameter, which would be an enum type.
>
> It would then allow you to access the individual elements of that enum, in
> order of declaration, using a nearly identical interface as std::array<>
> (i.e either through enumerators, or operator[]).
You're asking for enum reflection. There are many proposals about that, both
restricted to enums as well as generic (reflection for everything). The
restricted proposals haven't gained much traction, so everything now depends
on the full reflection proposals being accepted.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/2426352.kqhfR8YEAN%40tjmaciei-mobl1.
.
Author: wei zhang <lala.willzhang@gmail.com>
Date: Tue, 20 Jun 2017 21:12:43 -0700 (PDT)
Raw View
------=_Part_1805_1313231126.1498018363948
Content-Type: multipart/alternative;
boundary="----=_Part_1806_864230015.1498018363949"
------=_Part_1806_864230015.1498018363949
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I won't think it can be done with only add lib.
For the samething I would suggest enum class will have a static const=20
variable array.
so that you could write
const auto & e =3DColor.array
=E5=9C=A8 2017=E5=B9=B46=E6=9C=8821=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC=
+8=E4=B8=8A=E5=8D=8811:34:28=EF=BC=8CHalfdan Ingvarsson=E5=86=99=E9=81=93=
=EF=BC=9A
>
> I'd like to propose a simple, but very useful utility class for the=20
> standard library: std::enum. =20
>
> All it does is take a template parameter, which would be an enum type.
>
> It would then allow you to access the individual elements of that enum, i=
n=20
> order of declaration, using a nearly identical interface as std::array<>=
=20
> (i.e either through enumerators, or operator[]).
>
> E.g:=20
>
> #include <iostream>
> #include <enum>
> #include <algorithm>
>
>
> enum Color { Red =3D 1, Green =3D 2, Blue =3D 23 };
>
>
> int main()
> {
> auto e =3D std::enum<Color>();
> for( auto v: e)
> {
> std::cout << "Elem: " << v << "\n";
> }
> std::cout << "Size: " << e.size() << "\n";
> std::cout << "Largest: " << std::max_element(e.begin(), e.end()) <<=20
> "\n";
> return 0;
> }
>
> Output:
> Elem: 1
> Elem: 2
> Elem: 23
> Size: 3
> Largest: 23
>
> I assume that this would have to take some form of a help from the=20
> compiler, similar to how std::underlying_type is implemented. However, th=
is=20
> would obviate the current set of hacks that either require macros, specia=
l=20
> class constructions, or other inconvenient forms.
>
>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/546143ae-5acd-4a0e-abde-4f712c51ca30%40isocpp.or=
g.
------=_Part_1806_864230015.1498018363949
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I won't think it can be done with only add lib.<div>Fo=
r the samething I would suggest enum class will have a static const variabl=
e array.</div><div>so that you could write</div><div><div class=3D"prettypr=
int" 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"><font color=3D"#0=
00000"><span style=3D"color: #008;" class=3D"styled-by-prettify">const</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">auto</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: #00=
0;" class=3D"styled-by-prettify"> e </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">=3D</span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">Color</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">array</span></font></div></code></div><br><br><div><br><br>=E5=9C=A8 2=
017=E5=B9=B46=E6=9C=8821=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC+8=E4=B8=8A=
=E5=8D=8811:34:28=EF=BC=8CHalfdan Ingvarsson=E5=86=99=E9=81=93=EF=BC=9A<blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">I'd like to p=
ropose a simple, but very useful utility class for the standard library: st=
d::enum. =C2=A0<div><br></div><div>All it does is take a template parameter=
, which would be an enum type.</div><div><br></div><div>It would then allow=
you to access the individual elements of that enum, in order of declaratio=
n, using a nearly identical interface as std::array<> (i.e either thr=
ough enumerators, or operator[]).</div><div><div><br></div><div>E.g:=C2=A0<=
/div><div><br></div><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:#800">#include</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#080"><iostream></span><span =
style=3D"color:#000"><br></span><span style=3D"color:#800">#include</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080"><enum></=
span><span style=3D"color:#000"><br></span><span style=3D"color:#800">#incl=
ude</span><span style=3D"color:#000"> </span><span style=3D"color:#080"><=
;algorithm></span><span style=3D"color:#000"><br><br><br></span><span st=
yle=3D"color:#008">enum</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#606">Color</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#606">Red</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">=3D</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:#606">Green</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#066">2</span><span style=3D"color:#660">,</span><=
span style=3D"color:#000"> </span><span style=3D"color:#606">Blue</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><span =
style=3D"color:#000"> </span><span style=3D"color:#066">23</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">};</span><span style=3D=
"color:#000"><br><br><br></span><span style=3D"color:#008">int</span><span =
style=3D"color:#000"> main</span><span style=3D"color:#660">()</span><span =
style=3D"color:#000"><br></span><span style=3D"color:#660">{</span><span st=
yle=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=3D"color:#008">auto<=
/span><span style=3D"color:#000"> e </span><span style=3D"color:#660">=3D</=
span><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</s=
pan><span style=3D"color:#008">enum</span><span style=3D"color:#660"><</=
span><span style=3D"color:#606">Color</span><span style=3D"color:#660">>=
();</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=3D=
"color:#008">for</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">auto</span><span style=3D"colo=
r:#000"> v</span><span style=3D"color:#660">:</span><span style=3D"color:#0=
00"> e</span><span style=3D"color:#660">)</span><span style=3D"color:#000">=
<br>=C2=A0 =C2=A0</span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"><br>=C2=A0 =C2=A0 =C2=A0std</span><span style=3D"color:#660">::<=
/span><span style=3D"color:#000">cout </span><span style=3D"color:#660"><=
;<</span><span style=3D"color:#000"> </span><span style=3D"color:#080">&=
quot;Elem: "</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660"><<</span><span style=3D"color:#000"> v </span><span style=
=3D"color:#660"><<</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#080">"\n"</span><span style=3D"color:#660">;</span><=
span style=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=3D"color:#660=
">}</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">cout </span><span style=
=3D"color:#660"><<</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#080">"Size: "</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660"><<</span><span style=3D"color:#000"> e<=
/span><span style=3D"color:#660">.</span><span style=3D"color:#000">size</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"> </spa=
n><span style=3D"color:#080">"\n"</span><span style=3D"color:#660=
">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">cout </span><span style=
=3D"color:#660"><<</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#080">"Largest: "</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660"><<</span><span style=3D"color:#000">=
std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">m=
ax_element</span><span style=3D"color:#660">(</span><span style=3D"color:#0=
00">e</span><span style=3D"color:#660">.</span><span style=3D"color:#008">b=
egin</span><span style=3D"color:#660">(),</span><span style=3D"color:#000">=
e</span><span style=3D"color:#660">.</span><span style=3D"color:#008">end<=
/span><span style=3D"color:#660">())</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660"><<</span><span style=3D"color:#000"> </=
span><span style=3D"color:#080">"\n"</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=
=3D"color:#008">return</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">0</span><span style=3D"color:#660">;</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#660">}</span></div></code></div=
><div><font face=3D"courier new, monospace"><br></font></div><div><font fac=
e=3D"arial, sans-serif">Output:</font></div><div style=3D"background-color:=
rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-wi=
dth:1px;word-wrap:break-word"><code><div><span style=3D"color:#606">Elem</s=
pan><span style=3D"color:#660">:</span><span style=3D"color:#000"> </span><=
span style=3D"color:#066">1</span><span style=3D"color:#000"><br></span><sp=
an style=3D"color:#606">Elem</span><span style=3D"color:#660">:</span><span=
style=3D"color:#000"> </span><span style=3D"color:#066">2</span><span styl=
e=3D"color:#000"><br></span><span style=3D"color:#606">Elem</span><span sty=
le=3D"color:#660">:</span><span style=3D"color:#000"> </span><span style=3D=
"color:#066">23</span><span style=3D"color:#000"><br></span><span style=3D"=
color:#606">Size</span><span style=3D"color:#660">:</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">3</span><span style=3D"color:#=
000"><br></span><span style=3D"color:#606">Largest</span><span style=3D"col=
or:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">23</span></div></code></div><div><font face=3D"courier new, monospace">=
<br></font></div><div>I assume that this would have to take some form of a =
help from the compiler, similar to how std::underlying_type is implemented.=
However, this would obviate the current set of hacks that either require m=
acros, special class constructions, or other inconvenient forms.</div></div=
><div><br></div></div></blockquote></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/546143ae-5acd-4a0e-abde-4f712c51ca30%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/546143ae-5acd-4a0e-abde-4f712c51ca30=
%40isocpp.org</a>.<br />
------=_Part_1806_864230015.1498018363949--
------=_Part_1805_1313231126.1498018363948--
.
Author: Halfdan Ingvarsson <halfdan@gmail.com>
Date: Wed, 21 Jun 2017 05:34:29 -0700 (PDT)
Raw View
------=_Part_4702_2035059246.1498048469754
Content-Type: multipart/alternative;
boundary="----=_Part_4703_1517395180.1498048469754"
------=_Part_4703_1517395180.1498048469754
Content-Type: text/plain; charset="UTF-8"
On Wednesday, June 21, 2017 at 12:06:54 AM UTC-4, Thiago Macieira wrote:
>
> On Tuesday, 20 June 2017 20:34:28 PDT Halfdan Ingvarsson wrote:
> > I'd like to propose a simple, but very useful utility class for the
> > standard library: std::enum.
>
> You need to find a different name. We can't have a class whose name is a
> reserved keyword.
>
Er. Yes. std::enum_array. It got lost in the wash.
> You're asking for enum reflection. There are many proposals about that,
> both
> restricted to enums as well as generic (reflection for everything). The
> restricted proposals haven't gained much traction, so everything now
> depends
> on the full reflection proposals being accepted.
>
Indeed.
So far, the only proposal I've seen where I can easily enumerate an enum in
a for-each, is the one from Sutton and Sutter (P0590R0). The rest are a
form of a <foo>::get<I>() template, where, if the proposal doesn't include
it, one would be forced to write some variadic template magic to cover that
aspect.
However, the front-runner reflection proposals all rely on the existence of
concepts in the standard, which makes me think that we're nowhere near
anything resembling reflection for a long time indeed.
--
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/1dea3831-d801-43ab-9888-40b8364c3f7e%40isocpp.org.
------=_Part_4703_1517395180.1498048469754
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, June 21, 2017 at 12:06:54 AM UTC-4, Thiago M=
acieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Tuesday, 20 J=
une 2017 20:34:28 PDT Halfdan Ingvarsson wrote:
<br>> I'd like to propose a simple, but very useful utility class fo=
r the
<br>> standard library: std::enum.
<br>
<br>You need to find a different name. We can't have a class whose name=
is a=20
<br>reserved keyword.
<br></blockquote><div><br></div><div>Er. Yes. std::enum_array. It got lost =
in the wash.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;">You're asking for enum reflection. There are many proposals about=
that, both=20
<br>restricted to enums as well as generic (reflection for everything). The=
=20
<br>restricted proposals haven't gained much traction, so everything no=
w depends=20
<br>on the full reflection proposals being accepted.
<br></blockquote><div><br></div><div>Indeed.=C2=A0</div><div><br></div><div=
>So far, the only proposal I've seen where I can easily enumerate an en=
um in a for-each, is the one from Sutton and Sutter (P0590R0). The rest are=
a form of a <foo>::get<I>() template, where, if the proposal d=
oesn't include it, one would be forced to write some variadic template =
magic to cover that aspect.</div><div><br></div><div>However, the front-run=
ner reflection proposals all rely on the existence of concepts in the stand=
ard, which makes me think that we're nowhere near anything resembling r=
eflection for a long time indeed.</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1dea3831-d801-43ab-9888-40b8364c3f7e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1dea3831-d801-43ab-9888-40b8364c3f7e=
%40isocpp.org</a>.<br />
------=_Part_4703_1517395180.1498048469754--
------=_Part_4702_2035059246.1498048469754--
.
Author: Halfdan Ingvarsson <halfdan@gmail.com>
Date: Wed, 21 Jun 2017 05:38:53 -0700 (PDT)
Raw View
------=_Part_3150_985148847.1498048733266
Content-Type: multipart/alternative;
boundary="----=_Part_3151_427242366.1498048733266"
------=_Part_3151_427242366.1498048733266
Content-Type: text/plain; charset="UTF-8"
On Wednesday, June 21, 2017 at 12:12:44 AM UTC-4, wei zhang wrote:
>
> I won't think it can be done with only add lib.
> For the samething I would suggest enum class will have a static const
> variable array.
> so that you could write
> const auto & e =Color.array
>
That's why I mentioned that it would have to have some help from the
compiler.
For example, std::underlying_type, on clang and gcc, rely on an intrinsic
called __underlying_type(), which takes a type argument. In this case there
needs to be something like __enum_members(), which would be substituted by
an braced init list that contains the enum members at compile time.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88f0eeb9-c80f-4245-8231-bddacda98832%40isocpp.org.
------=_Part_3151_427242366.1498048733266
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, June 21, 2017 at 12:12:44 AM UTC-4, =
wei zhang 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"lt=
r">I won't think it can be done with only add lib.<div>For the samethin=
g I would suggest enum class will have a static const variable array.</div>=
<div>so that you could write</div><div><div 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><div><font color=3D"#000000"><span style=3D"=
color:#008">const</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">auto</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">&</span><span style=3D"color:#000"> e </span><span style=3D"co=
lor:#660">=3D</span><span style=3D"color:#606">Color</span><span style=3D"c=
olor:#660">.</span><span style=3D"color:#000">array</span></font></div></co=
de></div></div></div></blockquote><div><br></div><div>That's why I ment=
ioned that it would have to have some help from the compiler.</div><div><br=
></div><div>For example, std::underlying_type, on clang and gcc, rely on an=
intrinsic called __underlying_type(), which takes a type argument. In this=
case there needs to be something like __enum_members(), which would be sub=
stituted by an braced init list that contains the enum members at compile t=
ime.</div><div><br></div><style type=3D"text/css">
p, li { white-space: pre-wrap; }
</style>
</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/88f0eeb9-c80f-4245-8231-bddacda98832%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/88f0eeb9-c80f-4245-8231-bddacda98832=
%40isocpp.org</a>.<br />
------=_Part_3151_427242366.1498048733266--
------=_Part_3150_985148847.1498048733266--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 21 Jun 2017 07:17:57 -0700
Raw View
On Wednesday, 21 June 2017 05:34:29 PDT Halfdan Ingvarsson wrote:
> However, the front-runner reflection proposals all rely on the existence of
> concepts in the standard, which makes me think that we're nowhere near
> anything resembling reflection for a long time indeed.
No, we're not. But since the proposals for restricted reflection haven't gained
much traction, then it seems like we'll have to wait for the generic solution.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/2384155.IuquL1aeVr%40tjmaciei-mobl1.
.
Author: Patrice Roy <patricer@gmail.com>
Date: Thu, 22 Jun 2017 21:04:14 -0400
Raw View
--f403043c64580869d40552962e38
Content-Type: text/plain; charset="UTF-8"
Since the Issaquah meeting, reflection seems to be getting more and more
realistic. I think there's legitimate space for hope in the near (non-17)
future...
2017-06-21 10:17 GMT-04:00 Thiago Macieira <thiago@macieira.org>:
> On Wednesday, 21 June 2017 05:34:29 PDT Halfdan Ingvarsson wrote:
> > However, the front-runner reflection proposals all rely on the existence
> of
> > concepts in the standard, which makes me think that we're nowhere near
> > anything resembling reflection for a long time indeed.
>
> No, we're not. But since the proposals for restricted reflection haven't
> gained
> much traction, then it seems like we'll have to wait for the generic
> solution.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel Open Source Technology Center
>
> --
> 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/2384155.IuquL1aeVr%40tjmaciei-mobl1.
>
--
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/CAKiZDp0R3J4JKs%2BgpLqaJ2Uffgz%3DvTOvgXo-wPUvnRR_QnANzg%40mail.gmail.com.
--f403043c64580869d40552962e38
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Since the Issaquah meeting, reflection seems to be getting=
more and more realistic. I think there's legitimate space for hope in =
the near (non-17) future...<br></div><div class=3D"gmail_extra"><br><div cl=
ass=3D"gmail_quote">2017-06-21 10:17 GMT-04:00 Thiago Macieira <span dir=3D=
"ltr"><<a href=3D"mailto:thiago@macieira.org" target=3D"_blank">thiago@m=
acieira.org</a>></span>:<br><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=
=3D"">On Wednesday, 21 June 2017 05:34:29 PDT Halfdan Ingvarsson wrote:<br>
> However, the front-runner reflection proposals all rely on the existen=
ce of<br>
> concepts in the standard, which makes me think that we're nowhere =
near<br>
> anything resembling reflection for a long time indeed.<br>
<br>
</span>No, we're not. But since the proposals for restricted reflection=
haven't gained<br>
much traction, then it seems like we'll have to wait for the generic so=
lution.<br>
<span class=3D""><br>
--<br>
Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" rel=3D"noref=
errer" target=3D"_blank">macieira.info</a> - thiago (AT) <a href=3D"http://=
kde.org" rel=3D"noreferrer" target=3D"_blank">kde.org</a><br>
=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center<br>
<br>
</span><span class=3D"">--<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%2Bunsubscribe@isocpp.org">std-propo=
sals+unsubscribe@<wbr>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>
</span>To view this discussion on the web visit <a href=3D"https://groups.g=
oogle.com/a/isocpp.org/d/msgid/std-proposals/2384155.IuquL1aeVr%40tjmaciei-=
mobl1" rel=3D"noreferrer" target=3D"_blank">https://groups.google.com/a/<wb=
r>isocpp.org/d/msgid/std-<wbr>proposals/2384155.IuquL1aeVr%<wbr>40tjmaciei-=
mobl1</a>.<br>
</blockquote></div><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAKiZDp0R3J4JKs%2BgpLqaJ2Uffgz%3DvTOv=
gXo-wPUvnRR_QnANzg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAKiZDp0R3J4J=
Ks%2BgpLqaJ2Uffgz%3DvTOvgXo-wPUvnRR_QnANzg%40mail.gmail.com</a>.<br />
--f403043c64580869d40552962e38--
.
Author: Mingxin Wang <wmx16835vv@163.com>
Date: Thu, 22 Jun 2017 20:18:53 -0700 (PDT)
Raw View
------=_Part_204_941194325.1498187933254
Content-Type: multipart/alternative;
boundary="----=_Part_205_1179142056.1498187933254"
------=_Part_205_1179142056.1498187933254
Content-Type: text/plain; charset="UTF-8"
On Wednesday, June 21, 2017 at 11:34:28 AM UTC+8, Halfdan Ingvarsson wrote:
>
> I'd like to propose a simple, but very useful utility class for the
> standard library: std::enum.
>
> All it does is take a template parameter, which would be an enum type.
>
> It would then allow you to access the individual elements of that enum, in
> order of declaration, using a nearly identical interface as std::array<>
> (i.e either through enumerators, or operator[]).
>
> Because this depends on new language features, I think the motivation in
converting a "enum" to an array is not explicit enough.
As a user to the enum, I usually care "the mapping between names and
values" more than "the order of declaration". Would it be more reasonable
to convert an enum to an initializer list? For example:
enum E { ZERO = 0, ONE = 1, TWO = 2 };
std::map<std::string, int> a = MAKE_MAP(E); // MALE_MAP(E) is equivalent to
{{"ZERO", 0}, {"ONE", 1}, {"TWO", 2}}
Still, I think there should be more motivation. As I can imagine, this
feature is helpful in debugging and exception information generation.
Mingxin Wang
--
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/ec30b779-62be-4bf6-aa93-51e281e93811%40isocpp.org.
------=_Part_205_1179142056.1498187933254
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, June 21, 2017 at 11:34:28 AM UTC+8, Halfdan =
Ingvarsson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">I'd like to propose a simple, but very useful utility class for the=
standard library: std::enum. =C2=A0<div><br></div><div>All it does is take=
a template parameter, which would be an enum type.</div><div><br></div><di=
v>It would then allow you to access the individual elements of that enum, i=
n order of declaration, using a nearly identical interface as std::array<=
;> (i.e either through enumerators, or operator[]).</div><div><div><br><=
/div></div></div></blockquote><div>Because this depends on new language fea=
tures, I think the motivation in converting a "enum" to an array =
is not explicit enough.</div><div><br></div><div>As a user to the enum, I u=
sually care "the mapping between names and values" more than &quo=
t;the order of declaration". Would it be more reasonable to convert an=
enum to an initializer list? For example:</div><div><br></div><div><div cl=
ass=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wra=
p: break-word; background-color: rgb(250, 250, 250);"><code class=3D"pretty=
print"><div class=3D"subprettyprint"><div class=3D"subprettyprint">enum E {=
ZERO =3D 0, ONE =3D 1, TWO =3D 2 };</div><div class=3D"subprettyprint">std=
::map<std::string, int> a =3D MAKE_MAP(E); // MALE_MAP(E) is equivale=
nt to {{"ZERO", 0}, {"ONE", 1}, {"TWO", 2}}</=
div></div></code></div><br>Still, I think there should be more motivation. =
As I can imagine, this feature is helpful in debugging and exception inform=
ation generation.</div><div><br></div><div>Mingxin Wang</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ec30b779-62be-4bf6-aa93-51e281e93811%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ec30b779-62be-4bf6-aa93-51e281e93811=
%40isocpp.org</a>.<br />
------=_Part_205_1179142056.1498187933254--
------=_Part_204_941194325.1498187933254--
.