Topic: minimal enum class improvements
Author: ricardofabianodeandrade@gmail.com
Date: Mon, 11 Feb 2013 05:55:35 -0800 (PST)
Raw View
------=_Part_7_19754698.1360590935717
Content-Type: text/plain; charset=ISO-8859-1
Hi all,
Many things were said time to time about who the enum is broken by big
names in the C++ community what I don't think needs to be repeated here.
We've got great suggestions in this forum for improving the enum but being
a bit realistic I'm afraid many won't be mature enough in time for C++14 or
even C++17 standards.
So I would like to describe here two minor improvements in the language
support for enum which can lead to even more improvements in future STL
implementations.
It's important to say, they're not new ideas (see Vicente Escriba ordinal
types in this forum and other enum libraries such as the experimental
boost.enum).
I'm just taking a step forward to make them minimal enough what might turn
them into better candidates for standardization.
Well, let's start this draft of a draft. :-)
*Request for change:*
Inclusion of the following features in the C++ language support for enum:
- Obtain the number of enumerators of a given enum type.
- Obtain the value of an enumerator of a given enumerator's index (or
order, or position) and its enum type.
*Example *(please note no syntax is being suggested initially, just a
[magic] placeholder):
enum class AnEnum : int { a = -1, b = 1000, c = 0 };
std::size_t enumerators = [magic]<AnEnum>();
AnEnum value = [magic]<AnEnum>(0);
*
*
*Suggested Implementation* (to the compiler vendors):
- Number of enumerators:
The compiler counts the number of enumerators within a given enum and
provides this information during compile-time at no cost.
- Enumerator value:
The compiler takes an index for the given enum type and provides the
respective enumerator value at no cost *IF *the expression can be
resolved in compile-time (such as const, constexpr, template deduction,
etc.).
Otherwise, *an immutable array with the length equal to the number of
enumerators of the given enum and based in its underlying type* is
created during compile-time and stored (somewhere) in the translation unit.
Any expression can use this information in run-time to obtain the
enumerator value (it's a O(1) operation with some space cost and you
only pay if use it).
Example:
AnEnum values[] = { AnEnum::a, AnEnum::b, AnEnum::c };
AnEnum value = values[0]; // is the same as [magic]<AnEnum>(0) during
run-time
*Uses*:
- enum pseudo-inheritance and/or sequence continuation.
Example:
enum class AnotherEnum { d = ([magic]<AnEnum>([magic]<AnEnum>() - 1) + 1)
}; // compile-time last<AnEnum>() would be handy here!
- Range based operations over a given enum type.
Example:
for(size_t i = 0; i < [magic]<AnEnum>(); ++i)
{ AnEnum value = [magic]<AnEnum>(i); }
- Implementation of the index (or order, or position) of a given
enumerator within an enum.
Example (can be greatly improved by STL vendors):
<typename T>
class enum_index
{
vector<AnEnum> values;
enum_index() {
values.resize([magic]<T>());
for(size_t i = 0; i < [magic]<AnEnum>(); ++i) { [i] = [magic]
<AnEnum>(i); }
}
size_t index(const T& value) const
{ return (std::find(values.begin(), values.end(), AnEnum::a) -
values.begin()); }
};
size_t index = enum_index<AnEnum>().index(AnEnum::a);
*Discussions on standardization* (AKA my opinions):
Although many can think about these two features (number of enumerators and
enumerator value) as a reflection proposal I don't totally agree with that.
C++ core language already provides limited compile-time information
accessible during run-time in the form of sizeof and typeid (being the last
heavier in terms of cost than this proposal).
The final form of this proposal would contain well thought keywords for
these features (or clever uses to the existing ones -- less likely), so
they can also be part of the core language.
The keyword chosen for this proposal could even serve as a base for future
C++ reflection ones (maybe the member keyword?).
One final question: instead going to SG7 (reflection) or SG9 (ranges)
should this proposal go directly to the EWG?
This is such a small improvement in terms of complexity and impact in the
C++ language but it has the potential of improving a lot the readability
and maintainability of any code which depends on enum to work properly.
Additions, reviews and feedback are welcome.
Thanks,
Ricardo Andrade
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
------=_Part_7_19754698.1360590935717
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi all,<div><br></div><div>Many things were said time to time about who the=
<font face=3D"courier new, monospace">enum</font> is broken by big na=
mes in the C++ community what I don't think needs to be repeated here.<br><=
/div><div><br></div><div>We've got great suggestions in this forum for impr=
oving the <font face=3D"courier new, monospace">enum</font> but being a bit=
realistic I'm afraid many won't be mature enough in time for C++14 or even=
C++17 standards.<br></div><div>So I would like to describe here two minor =
improvements in the language support for <font face=3D"courier new, monospa=
ce">enum</font> which can lead to even more improvements in future STL=
implementations.<br></div><div><br></div><div>It's important to say, they'=
re not new ideas (see Vicente Escriba ordinal types in this forum and other=
<font face=3D"courier new, monospace">enum</font> libraries such as the ex=
perimental boost.enum).</div><div>I'm just taking a step forward to make th=
em minimal enough what might turn them into better candidates for standardi=
zation.</div><div><br></div><div>Well, let's start this draft of a draft. :=
-)</div><div><br></div><div><b>Request for change:</b><br></div><div><br></=
div><div>Inclusion of the following features in the C++ language support fo=
r <font face=3D"courier new, monospace">enum</font>:</div><div><ul><li>Obta=
in the number of enumerators of a given <font face=3D"courier new, monospac=
e">enum</font> type.</li><li>Obtain the value of an enumerator of a gi=
ven enumerator's index (or order, or position) and its <font face=
=3D"courier new, monospace">enum</font> type.<br></li></ul><div><span style=
=3D"line-height: 17px;"><b>Example </b>(please note no syntax is =
being suggested initially, just a <font face=3D"courier new, monospace">[ma=
gic]</font> placeholder):</span></div></div><div style=3D"background-color:=
rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break=
-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"sub=
prettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">enum=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">AnEnum</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> a </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color: #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"> b </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #066;" class=3D"styled-by-prettify">1000</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> c </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" clas=
s=3D"styled-by-prettify">0</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">size_t enume=
rators </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">magic</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">]<</span><span style=3D"color:=
#606;" class=3D"styled-by-prettify">AnEnum</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">>();</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">AnEnum</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> value </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>[</span><span style=3D"color: #000;" class=3D"styled-by-prettify">magic</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">]<</span><=
span style=3D"color: #606;" class=3D"styled-by-prettify">AnEnum</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">>(</span><span styl=
e=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">);</span></div></code></div><div><di=
v><span style=3D"line-height: 17px;"><b><br></b></span></div><div><span sty=
le=3D"line-height: 17px;"><b>Suggested Implementation</b> (to the compiler =
vendors):</span></div></div><div><ul><li>Number of enumerators:<br>The comp=
iler counts the number of enumerators within a given <font face=3D"courier =
new, monospace">enum</font> and provides this information during compi=
le-time at no cost.</li><li>Enumerator value:<br>The compiler takes an=
index for the given <font face=3D"courier new, monospace">enum</font> type=
and provides the respective enumerator value at no cost <b>IF </b>the expr=
ession can be resolved in compile-time (such as <font face=3D"courier new, =
monospace">const</font>, <font face=3D"courier new, monospace">constexpr</f=
ont>, template deduction, etc.).<br>Otherwise, <u>an immutable array with t=
he length equal to the number of enumerators of the given enum and based in=
its underlying type</u> is created during compile-time and stored (somewhe=
re) in the translation unit.<br>Any expression can use this information in =
run-time to obtain the enumerator value (it's a <font face=3D"courier new, =
monospace">O(1)</font> operation with some space cost and you only pay if u=
se it).<br>Example:<br><font face=3D"courier new, monospace"><div style=3D"=
background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187);=
word-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprint">=
<div class=3D"subprettyprint"><span style=3D"color: #606;" class=3D"styled-=
by-prettify">AnEnum</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> values</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">[]</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;"=
class=3D"styled-by-prettify">AnEnum</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">AnEnum</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">b</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">AnEnum</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">c </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span><span style=3D"color: #606;" class=3D"styled-by-prettify">AnEnu=
m</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> value </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> values</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">];</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">// is the same as [magic]<AnEnum>(0) during run-tim=
e</span></div></code></div></font></li></ul></div><div><b>Uses</b>:</div><d=
iv><ul><li><font face=3D"courier new, monospace" style=3D"line-height: norm=
al;">enum</font><span style=3D"line-height: normal;"> pseudo-inheritan=
ce and/or sequence continuation.<br></span><span style=3D"line-height:=
normal;">Example:</span><br><div style=3D"background-color: rgb(250, 250, =
250); border: 1px solid rgb(187, 187, 187); word-wrap: break-word;" class=
=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #008;" class=3D"styled-by-prettify">enum</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">AnotherEnum</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-b=
y-prettify"> d </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">=3D</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">magic</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">]<</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">AnEnum</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">>([</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">magic</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">]<</span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">AnEnum</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">>()</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">-</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">+</span><span style=3D"color: #00=
0;" 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"style=
d-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">};<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #800;" class=3D"styled-by-prettify">// compile-time last=
<AnEnum>() would be handy here!</span></div></code></div></li><li><sp=
an style=3D"line-height: normal;">Range based operations over a given <font=
face=3D"courier new, monospace">enum</font> type.<br>Example:<br><div styl=
e=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, =
187); word-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettypr=
int"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">for</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">size_t i </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> i </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">[</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">magic</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">]<</span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>AnEnum</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>=
;();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">++</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">i</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">AnEnum</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> value </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</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">magic</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">]<</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">AnEnum</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">>(</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">i</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</span></div></code></div></span></li><li>Implementation of the in=
dex (or order, or position) of a given enumerator within an <font face=3D"c=
ourier new, monospace">enum</font>.<br>Example (can be greatly improved by =
STL vendors):<br><font face=3D"courier new, monospace"><div style=3D"backgr=
ound-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-=
wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div c=
lass=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify"><typename</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
T</span><span style=3D"color: #008;" class=3D"styled-by-prettify">></spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>class enum_=
index<br>{<br> vector</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify"><AnEnum></span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> values;<br> enum_index() {<br>&nb=
sp; values.resize([magic]</span><span style=3D"color: =
#008;" class=3D"styled-by-prettify"><T></span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">());<br> for(=
size_t i =3D 0; i < [magic]</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify"><AnEnum></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">(); ++i) { [i] =3D [magic]</span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify"><AnEnum></span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">(i); }<br> }<br>&n=
bsp; size_t index(const T& value) const<br> { retur=
n (std::find(values.begin(), values.end(), AnEnum::a) - values.begin()); }<=
br>};<br>size_t index =3D enum_index</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify"><AnEnum></span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">().index(AnEnum::a);</span></div></code></div=
></font></li></ul></div><div><b>Discussions on standardization</b> (AKA my =
opinions):</div><blockquote style=3D"margin: 0 0 0 40px; border: none; padd=
ing: 0px;"><div>Although many can think about these two features (number of=
enumerators and enumerator value) as a reflection proposal I don't totally=
agree with that.</div></blockquote><div> </div><blockquote style=3D"m=
argin: 0 0 0 40px; border: none; padding: 0px;"><div>C++ core language alre=
ady provides limited compile-time information accessible during run-time in=
the form of <font face=3D"courier new, monospace">sizeof</font> and <=
font face=3D"courier new, monospace">typeid</font> (being the last hea=
vier in terms of cost than this proposal).</div></blockquote><blockquote st=
yle=3D"margin: 0 0 0 40px; border: none; padding: 0px;"><div>The final form=
of this proposal would contain well thought keywords for these features (o=
r clever uses to the existing ones -- less likely), so they can also be par=
t of the core language.</div></blockquote><blockquote style=3D"margin: 0 0 =
0 40px; border: none; padding: 0px;"><div>The keyword chosen for this propo=
sal could even serve as a base for future C++ reflection ones (maybe the <f=
ont face=3D"courier new, monospace">member</font> keyword?).</div></blockqu=
ote><div> </div><blockquote style=3D"margin: 0 0 0 40px; border: none;=
padding: 0px;"><div>One final question: instead going to SG7 (reflection) =
or SG9 (ranges) should this proposal go directly to the EWG?</div=
></blockquote><div><br>This is such a small improvement in terms of complex=
ity and impact in the C++ language but it has the potential of improving a =
lot the readability and maintainability of any code which depends=
on <font face=3D"courier new, monospace">enum</font> to work properly.</di=
v><div><br></div><div>Additions, reviews and feedback are welcome.</div><di=
v><br></div><div>Thanks,</div><div>Ricardo Andrade</div><div><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_7_19754698.1360590935717--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 11 Feb 2013 08:44:13 -0800 (PST)
Raw View
------=_Part_301_11027089.1360601053466
Content-Type: text/plain; charset=ISO-8859-1
On Monday, February 11, 2013 5:55:35 AM UTC-8, ricardofabi...@gmail.com
wrote:
>
> One final question: instead going to SG7 (reflection) or SG9 (ranges)
> should this proposal go directly to the EWG?
>
>
> This is such a small improvement in terms of complexity and impact in the
> C++ language but it has the potential of improving a lot the readability
> and maintainability of any code which depends on enum to work properly.
>
It may be a "small improvement", but it is also unquestionably *reflection*.
Which is something that's being actively pursued. What we don't want is an
independent proposal introducing a reflection mechanism that works contrary
to whatever mechanism SG7 comes up with. So it should go to them, but
really, I don't see why you'd need to propose it. Whatever reflection
mechanisms they come up with will include enum reflection.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
------=_Part_301_11027089.1360601053466
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>On Monday, February 11, 2013 5:55:35 AM UTC-8, ricardofabi...@gmail=
..com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><blockquote style=
=3D"margin:0 0 0 40px;border:none;padding:0px"><div>One final question: ins=
tead going to SG7 (reflection) or SG9 (ranges) should this proposal go dire=
ctly to the EWG?</div></blockquote><div><br>This is such a small =
improvement in terms of complexity and impact in the C++ language but it ha=
s the potential of improving a lot the readability and maintainability=
of any code which depends on <font face=3D"courier new, monospace">en=
um</font> to work properly.</div></blockquote><div><br>It may be a "small i=
mprovement", but it is also unquestionably <i>reflection</i>. Which is some=
thing that's being actively pursued. What we don't want is an independent p=
roposal introducing a reflection mechanism that works contrary to whatever =
mechanism SG7 comes up with. So it should go to them, but really, I don't s=
ee why you'd need to propose it. Whatever reflection mechanisms they come u=
p with will include enum reflection.<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_301_11027089.1360601053466--
.
Author: ricardofabianodeandrade@gmail.com
Date: Mon, 11 Feb 2013 12:24:00 -0800 (PST)
Raw View
------=_Part_1285_29905042.1360614240308
Content-Type: text/plain; charset=ISO-8859-1
Hi Nicol,
I hope we are not seeing another "concepts" case here.
I'll keep myself updated on the SG7 work.
Thanks for your reply.
Ricardo
On Monday, February 11, 2013 2:44:13 PM UTC-2, Nicol Bolas wrote:
>
>
>
> On Monday, February 11, 2013 5:55:35 AM UTC-8, ricardofabi...@gmail.comwrote:
>>
>> One final question: instead going to SG7 (reflection) or SG9 (ranges)
>> should this proposal go directly to the EWG?
>>
>>
>> This is such a small improvement in terms of complexity and impact in the
>> C++ language but it has the potential of improving a lot the readability
>> and maintainability of any code which depends on enum to work properly.
>>
>
> It may be a "small improvement", but it is also unquestionably *reflection
> *. Which is something that's being actively pursued. What we don't want
> is an independent proposal introducing a reflection mechanism that works
> contrary to whatever mechanism SG7 comes up with. So it should go to them,
> but really, I don't see why you'd need to propose it. Whatever reflection
> mechanisms they come up with will include enum reflection.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
------=_Part_1285_29905042.1360614240308
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi Nicol,<div><br></div><div>I hope we are not seeing another "concepts" ca=
se here.</div><div>I'll keep myself updated on the SG7 work.</div><div><br>=
</div><div>Thanks for your reply.</div><div>Ricardo</div><div><br><br>On Mo=
nday, February 11, 2013 2:44:13 PM UTC-2, Nicol Bolas wrote:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><br><br>On Monday, February 11, 2013 5:55:35 =
AM UTC-8, <a>ricardofabi...@gmail.com</a> wrote:<blockquote class=3D"gmail_=
quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;paddi=
ng-left:1ex"><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px=
"><div>One final question: instead going to SG7 (reflection) or SG9 (ranges=
) should this proposal go directly to the EWG?</div></blockquote>=
<div><br>This is such a small improvement in terms of complexity and impact=
in the C++ language but it has the potential of improving a lot the readab=
ility and maintainability of any code which depends on <font face=
=3D"courier new, monospace">enum</font> to work properly.</div></blockquote=
><div><br>It may be a "small improvement", but it is also unquestionably <i=
>reflection</i>. Which is something that's being actively pursued. What we =
don't want is an independent proposal introducing a reflection mechanism th=
at works contrary to whatever mechanism SG7 comes up with. So it should go =
to them, but really, I don't see why you'd need to propose it. Whatever ref=
lection mechanisms they come up with will include enum reflection.<br></div=
></blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_1285_29905042.1360614240308--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Tue, 12 Feb 2013 21:10:10 +0100
Raw View
This is a multi-part message in MIME format.
--------------010601020506020504060100
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 11/02/13 14:55, ricardofabianodeandrade@gmail.com a =E9crit :
> Hi all,
>
>
>
> *Request for change:*
>
> Inclusion of the following features in the C++ language support for enum:
>
> * Obtain the number of enumerators of a given enum type.
> * Obtain the value of an enumerator of a given enumerator's index
> (or order, or position) and its enum type.
>
I would add to the minimal set of features this
| * obtain |the position relative of an enumeration value in the=20
enum type.
This requires of course that all the enumerations have a distinct value.=20
The compiler could not provide these meta-functions if the enum doesn't=20
satisfy this condition.
In addition, the allowed values of an 'ordinal' enumeration type should=20
contain only the enumerations because otherwise the pos function could=20
not be defined. This is a breaking change or require adding a specific=20
syntax for 'ordinal' enumeration. Maybe using a new *ordinal* keyword=20
instead of enum could be an option
|*ordinal*classAnEnum:int{a =3D-1,b =3D1000,c =3D0};
|
> *Example *(please note no syntax is being suggested initially, just a=20
> [magic] placeholder):
> |
> enumclassAnEnum:int{a =3D-1,b =3D1000,c =3D0};
> std::size_t enumerators =3D[magic]<AnEnum>();
> AnEnumvalue =3D[magic]<AnEnum>(0);
> |
> *
> *
I find this syntax a little bit obscure. I would prefer specific=20
functions as size, val and pos.
template <typename EC>
constexpr std::size_t size() noexcept;
template <typename EC>
constexpr EC val(std::size_t) noexcept;
template <typename EC>
constexpr std::size_t pos(EC) noexcept;
|
enumclassAnEnum:int{a =3D-1,b =3D1000,c =3D0};
||||
constexpr ||||std::size_t enumerators =3Dsize<AnEnum>();|||
||||||||||
|||||
|||||||||||||
constexpr AnEnume2 =3Dval<AnEnum>(1);
| |||||||std::size_t n =3D 6;||||||||
||||||||||AnEnume2 =3Dval<AnEnum>(n); //runtime
|
||
|||||||||
|||||constexpr ||||std::size_t|indx =3D||pos(||||||||AnEnum::a||||||||);
| ||||||||||
|std::size_t|indx =3Dpos(e2); |||//runtime|||
|
*
*
|||
|
The pos runtime function could use the same algorithm the compiler uses=20
for a switch.
The constexpr pos function could be replaced directly at compile time.
first, last, succ and pred functions can be defined easily as follows
template <typename EC>
constexpr EC first() noexcept
{
return val<EC>(0);
}
template <typename EC>
constexpr EC last() noexcept
{
return val<EC>(size<EC>()-1);
}
template <typename EC>
constexpr EC succ(EC e)
{
//assert(pos(e)!=3D(size<EC>()-1));
return val<EC>(pos(e)+1);
}
template <typename EC>
constexpr EC pred(EC e)
{
//assert(pos(e)!=3D0);
return val<EC>(pos(e)-1);
}
Best,
Vicente
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
--------------010601020506020504060100
Content-Type: text/html; charset=ISO-8859-1
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Le 11/02/13 14:55,
<a class="moz-txt-link-abbreviated" href="mailto:ricardofabianodeandrade@gmail.com">ricardofabianodeandrade@gmail.com</a> a écrit :<br>
</div>
<blockquote
cite="mid:c15b7b1c-6d6f-4472-8a43-b2fb374b92a1@isocpp.org"
type="cite">Hi all,
<div><br>
</div>
<br>
<div><br>
</div>
<div><b>Request for change:</b><br>
</div>
<div><br>
</div>
<div>Inclusion of the following features in the C++ language
support for <font face="courier new, monospace">enum</font>:</div>
<div>
<ul>
<li>Obtain the number of enumerators of a given <font
face="courier new, monospace">enum</font> type.</li>
<li>Obtain the value of an enumerator of a given enumerator's
index (or order, or position) and its <font face="courier
new, monospace">enum</font> type.<br>
</li>
</ul>
</div>
</blockquote>
<br>
I would add to the minimal set of features this<br>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<code class="computeroutput"><span class="identifier"> * obtain
</span></code>the position relative of an enumeration value in the
enum type. <br>
<br>
This requires of course that all the enumerations have a distinct
value. The compiler could not provide these meta-functions if the
enum doesn't satisfy this condition. <br>
In addition, the allowed values of an 'ordinal' enumeration type
should contain only the enumerations because otherwise the pos
function could not be defined. This is a breaking change or require
adding a specific syntax for 'ordinal' enumeration. Maybe using a
new <b>ordinal</b> keyword instead of enum could be an option<br>
<br>
<code class="prettyprint"><b><span style="color: #008;"
class="styled-by-prettify">ordinal</span></b><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">class</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">AnEnum</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">:</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">int</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">{</span><span
style="color: #000;" class="styled-by-prettify"> a </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">-</span><span
style="color: #066;" class="styled-by-prettify">1</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> b </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">1000</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> c </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">0</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">};</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span></code><br>
<br>
<blockquote
cite="mid:c15b7b1c-6d6f-4472-8a43-b2fb374b92a1@isocpp.org"
type="cite">
<div>
<div><span style="line-height: 17px;"><b>Example </b>(please
note no syntax is being suggested initially, just a <font
face="courier new, monospace">[magic]</font> placeholder):</span></div>
</div>
<div style="background-color: rgb(250, 250, 250); border: 1px
solid rgb(187, 187, 187); word-wrap: break-word;"
class="prettyprint"><code class="prettyprint">
<div class="subprettyprint"><span style="color: #008;"
class="styled-by-prettify">enum</span><span style="color:
#000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">class</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">AnEnum</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">:</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">int</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">{</span><span
style="color: #000;" class="styled-by-prettify"> a </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">-</span><span
style="color: #066;" class="styled-by-prettify">1</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> b </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">1000</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> c </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">0</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">};</span><span
style="color: #000;" class="styled-by-prettify"><br>
std</span><span style="color: #660;"
class="styled-by-prettify">::</span><span style="color:
#000;" class="styled-by-prettify">size_t enumerators </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">[</span><span
style="color: #000;" class="styled-by-prettify">magic</span><span
style="color: #660;" class="styled-by-prettify">]<</span><span
style="color: #606;" class="styled-by-prettify">AnEnum</span><span
style="color: #660;" class="styled-by-prettify">>();</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #606;" class="styled-by-prettify">AnEnum</span><span
style="color: #000;" class="styled-by-prettify"> value </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">[</span><span
style="color: #000;" class="styled-by-prettify">magic</span><span
style="color: #660;" class="styled-by-prettify">]<</span><span
style="color: #606;" class="styled-by-prettify">AnEnum</span><span
style="color: #660;" class="styled-by-prettify">>(</span><span
style="color: #066;" class="styled-by-prettify">0</span><span
style="color: #660;" class="styled-by-prettify">);</span></div>
</code></div>
<div>
<div><span style="line-height: 17px;"><b><br>
</b></span></div>
</div>
</blockquote>
I find this syntax a little bit obscure. I would prefer specific
functions as size, val and pos.<br>
<br>
template <typename EC><br>
constexpr std::size_t size() noexcept;<br>
template <typename EC><br>
constexpr EC val(std::size_t) noexcept;<br>
template <typename EC><br>
constexpr std::size_t pos(EC) noexcept;<br>
<br>
<br>
<div style="background-color: rgb(250, 250, 250); border: 1px solid
rgb(187, 187, 187); word-wrap: break-word;" class="prettyprint"><code
class="prettyprint">
<div class="subprettyprint"><span style="color: #008;"
class="styled-by-prettify">enum</span><span style="color:
#000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">class</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">AnEnum</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">:</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">int</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">{</span><span
style="color: #000;" class="styled-by-prettify"> a </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">-</span><span
style="color: #066;" class="styled-by-prettify">1</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> b </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">1000</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> c </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">0</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">};</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #000;" class="styled-by-prettify"><code
class="prettyprint"><code class="prettyprint"><code
class="prettyprint"><code class="prettyprint"><span
style="color: #606;" class="styled-by-prettify"><br>
constexpr </span></code></code></code></code>std</span><span
style="color: #660;" class="styled-by-prettify">::</span><span
style="color: #000;" class="styled-by-prettify">size_t
enumerators </span><span style="color: #660;"
class="styled-by-prettify">=</span><span style="color:
#000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">size</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #606;" class="styled-by-prettify">AnEnum</span><span
style="color: #660;" class="styled-by-prettify">>();</span><span
style="color: #000;" class="styled-by-prettify"></span><code
class="prettyprint"><code class="prettyprint"><code
class="prettyprint">
<div class="subprettyprint"><br>
<span style="color: #606;" class="styled-by-prettify"><code
class="prettyprint"><span style="color: #000;"
class="styled-by-prettify"><code
class="prettyprint"><code class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><span style="color:
#606;" class="styled-by-prettify"></span></code></code></code></code></span></code></span></div>
</code></code></code><code class="prettyprint"><code
class="prettyprint">
<div class="subprettyprint"><span style="color: #606;"
class="styled-by-prettify"><code class="prettyprint"><code
class="prettyprint"><code class="prettyprint"><code
class="prettyprint"><span style="color: #606;"
class="styled-by-prettify"><code
class="prettyprint"><span style="color:
#000;" class="styled-by-prettify"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint">
<div
class="subprettyprint"><span
style="color: #606;"
class="styled-by-prettify">constexpr AnEnum</span><span style="color:
#000;"
class="styled-by-prettify">
e2 </span><span
style="color: #660;"
class="styled-by-prettify">=</span><span style="color: #000;"
class="styled-by-prettify">
</span><span
style="color: #660;"
class="styled-by-prettify">val</span><span style="color: #660;"
class="styled-by-prettify"><</span><span
style="color: #606;"
class="styled-by-prettify">AnEnum</span><span style="color: #660;"
class="styled-by-prettify">>(</span><span
style="color: #066;"
class="styled-by-prettify">1</span><span style="color: #660;"
class="styled-by-prettify">);<br>
</span></div>
</code>
</code></code></code></code></code></code></code>std</span><span
style="color: #660;"
class="styled-by-prettify">::</span><span
style="color: #000;"
class="styled-by-prettify">size_t n = 6;</span></code></span></code></code></code></code></span><code
class="prettyprint"><code class="prettyprint"><code
class="prettyprint">
<div class="subprettyprint"><span style="color:
#606;" class="styled-by-prettify"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><span
style="color: #606;"
class="styled-by-prettify"><code
class="prettyprint"><span
style="color: #000;"
class="styled-by-prettify"></span></code></span></code></code></code></code>AnEnum</span><span
style="color: #000;"
class="styled-by-prettify"> e2 </span><span
style="color: #660;"
class="styled-by-prettify">=</span><span
style="color: #000;"
class="styled-by-prettify"> </span><span
style="color: #660;"
class="styled-by-prettify">val</span><span
style="color: #660;"
class="styled-by-prettify"><</span><span
style="color: #606;"
class="styled-by-prettify">AnEnum</span><span
style="color: #660;"
class="styled-by-prettify">>(</span><span
style="color: #066;"
class="styled-by-prettify">n</span><span
style="color: #660;"
class="styled-by-prettify">); //runtime<br>
</span></div>
</code>
<div><br>
</div>
</code></code></div>
</code></code><code class="prettyprint"><code
class="prettyprint"><code class="prettyprint"><code
class="prettyprint"><code class="prettyprint"><code
class="prettyprint"><code class="prettyprint">
<div class="subprettyprint"><code
class="prettyprint"><span style="color:
#000;" class="styled-by-prettify"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><span
style="color: #606;"
class="styled-by-prettify">constexpr
</span></code></code></code></code>std</span><span
style="color: #660;"
class="styled-by-prettify">::</span><span
style="color: #000;"
class="styled-by-prettify">size_t</span></code><span
style="color: #000;"
class="styled-by-prettify"> indx </span><span
style="color: #660;"
class="styled-by-prettify">=</span><span
style="color: #000;"
class="styled-by-prettify"> </span><span
style="color: #000;"
class="styled-by-prettify"><code
class="prettyprint"><span style="color:
#000;" class="styled-by-prettify"></span></code>pos</span>(<code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><code
class="prettyprint"><span
style="color: #606;"
class="styled-by-prettify">AnEnum</span><span
style="color: #660;"
class="styled-by-prettify">::a</span></code></code></code></code></code></code></code></code><span
style="color: #066;"
class="styled-by-prettify"></span><span
style="color: #660;"
class="styled-by-prettify">);</span></div>
</code>
</code></code></code></code></code></code><code
class="prettyprint"><code class="prettyprint"><code
class="prettyprint"><code class="prettyprint">
<div class="subprettyprint"><code class="prettyprint"><span
style="color: #000;" class="styled-by-prettify">std</span><span
style="color: #660;" class="styled-by-prettify">::</span><span
style="color: #000;" class="styled-by-prettify">size_t</span></code><span
style="color: #000;" class="styled-by-prettify">
indx </span><span style="color: #660;"
class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #000;" class="styled-by-prettify">pos</span><span
style="color: #660;" class="styled-by-prettify">(</span>e2<span
style="color: #066;" class="styled-by-prettify"></span><span
style="color: #660;" class="styled-by-prettify">);
</span><code class="prettyprint"><code
class="prettyprint"><code class="prettyprint"><span
style="color: #660;"
class="styled-by-prettify">//runtime</span></code></code></code></div>
</code>
<div>
<div><span style="line-height: 17px;"><b><br>
</b></span></div>
</div>
</code></code></code></div>
</code></div>
<br>
The pos runtime function could use the same algorithm the compiler
uses for a switch. <br>
The constexpr pos function could be replaced directly at compile
time.<br>
<br>
first, last, succ and pred functions can be defined easily as
follows<br>
<br>
template <typename EC><br>
constexpr EC first() noexcept<br>
{<br>
return val<EC>(0);<br>
}<br>
template <typename EC><br>
constexpr EC last() noexcept<br>
{<br>
return val<EC>(size<EC>()-1);<br>
}<br>
<br>
template <typename EC><br>
constexpr EC succ(EC e)<br>
{<br>
//assert(pos(e)!=(size<EC>()-1));<br>
return val<EC>(pos(e)+1);<br>
}<br>
template <typename EC><br>
constexpr EC pred(EC e)<br>
{<br>
//assert(pos(e)!=0);<br>
return val<EC>(pos(e)-1);<br>
}<br>
<br>
Best,<br>
Vicente<br>
</body>
</html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en">http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en</a>.<br />
<br />
<br />
--------------010601020506020504060100--
.
Author: Tony V E <tvaneerd@gmail.com>
Date: Tue, 12 Feb 2013 15:15:14 -0500
Raw View
On Tue, Feb 12, 2013 at 3:10 PM, Vicente J. Botet Escriba
<vicente.botet@wanadoo.fr> wrote:
> Le 11/02/13 14:55, ricardofabianodeandrade@gmail.com a =E9crit :
>
> Hi all,
>
>
>
> Request for change:
>
> Inclusion of the following features in the C++ language support for enum:
>
> Obtain the number of enumerators of a given enum type.
> Obtain the value of an enumerator of a given enumerator's index (or order=
,
> or position) and its enum type.
>
>
> I would add to the minimal set of features this
> * obtain the position relative of an enumeration value in the enum
> type.
>
> This requires of course that all the enumerations have a distinct value. =
The
> compiler could not provide these meta-functions if the enum doesn't satis=
fy
> this condition.
> In addition, the allowed values of an 'ordinal' enumeration type should
> contain only the enumerations because otherwise the pos function could no=
t
> be defined. This is a breaking change or require adding a specific syntax
> for 'ordinal' enumeration. Maybe using a new ordinal keyword instead of e=
num
> could be an option
>
> ordinal class AnEnum : int { a =3D -1, b =3D 1000, c =3D 0 };
>
I happen to have code using the word 'ordinal', so I think I would prefer:
enum ordinal AnEnum : int { a =3D -1, b =3D 1000, c =3D 0 };
Also, how about some real world scenarios/code that would make good
use of these features? ie prove they are worth it.
Tony
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Tue, 12 Feb 2013 21:41:08 +0100
Raw View
Le 12/02/13 21:15, Tony V E a =E9crit :
> Also, how about some real world scenarios/code that would make good=20
> use of these features? ie prove they are worth it.=20
This paper "Flag waiving" by Kevlin Henney presents some scenarios where=20
ordinal enums could help to simplify higher abstractions.=20
(file://localhost/Users/viboes/Downloads/FlagWaiving.pdf).
Vicente
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.
Author: stackmachine@hotmail.com
Date: Mon, 18 Feb 2013 06:06:42 -0800 (PST)
Raw View
------=_Part_27_27973502.1361196402818
Content-Type: text/plain; charset=ISO-8859-1
- Flag enums
enum flags X{ foo, bar, baz };
X x = foo | bar;
if(x & baz)
x |= foo;
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
------=_Part_27_27973502.1361196402818
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<ul><li>Flag enums</li></ul><p></p><div class=3D"prettyprint" style=3D"back=
ground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-=
style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pre=
ttyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">enum</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> flags X</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> bar</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> baz </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>X x </span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> foo </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">|</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> bar</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">if</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">x </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> baz</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br> x </span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">|=3D</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span></div></code></div><br><br><p></p>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_27_27973502.1361196402818--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Mon, 18 Feb 2013 19:14:18 +0100
Raw View
This is a multi-part message in MIME format.
--------------050406000100090700020509
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 18/02/13 15:06, stackmachine@hotmail.com a =E9crit :
>
> * Flag enums
>
> |
> enumflags X{foo,bar,baz };
> X x =3Dfoo |bar;
> if(x &baz)
> x |=3Dfoo;
> |
>
>
Evidently this is not solution to flags sets.
Vicente
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
--------------050406000100090700020509
Content-Type: text/html; charset=ISO-8859-1
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Le 18/02/13 15:06,
<a class="moz-txt-link-abbreviated" href="mailto:stackmachine@hotmail.com">stackmachine@hotmail.com</a> a écrit :<br>
</div>
<blockquote
cite="mid:6ab52344-d0a5-4bd5-82cc-28bd0428734c@isocpp.org"
type="cite">
<ul>
<li>Flag enums</li>
</ul>
<div class="prettyprint" style="background-color: rgb(250, 250,
250); border-color: rgb(187, 187, 187); border-style: solid;
border-width: 1px; word-wrap: break-word;"><code
class="prettyprint">
<div class="subprettyprint"><span style="color: #008;"
class="styled-by-prettify">enum</span><span style="color:
#000;" class="styled-by-prettify"> flags X</span><span
style="color: #660;" class="styled-by-prettify">{</span><span
style="color: #000;" class="styled-by-prettify"> foo</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> bar</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> baz </span><span
style="color: #660;" class="styled-by-prettify">};</span><span
style="color: #000;" class="styled-by-prettify"><br>
X x </span><span style="color: #660;"
class="styled-by-prettify">=</span><span style="color:
#000;" class="styled-by-prettify"> foo </span><span
style="color: #660;" class="styled-by-prettify">|</span><span
style="color: #000;" class="styled-by-prettify"> bar</span><span
style="color: #660;" class="styled-by-prettify">;</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;" class="styled-by-prettify">if</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #000;" class="styled-by-prettify">x </span><span
style="color: #660;" class="styled-by-prettify">&</span><span
style="color: #000;" class="styled-by-prettify"> baz</span><span
style="color: #660;" class="styled-by-prettify">)</span><span
style="color: #000;" class="styled-by-prettify"><br>
x </span><span style="color: #660;"
class="styled-by-prettify">|=</span><span style="color:
#000;" class="styled-by-prettify"> foo</span><span
style="color: #660;" class="styled-by-prettify">;</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span></div>
</code></div>
<br>
<br>
</blockquote>
Evidently this is not solution to flags sets.<br>
<br>
Vicente<br>
</body>
</html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en">http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en</a>.<br />
<br />
<br />
--------------050406000100090700020509--
.