220 2808 <c15b7b1c-6d6f-4472-8a43-b2fb374b92a1@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: ricardofabianodeandrade@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: minimal enum class improvements
Date: Mon, 11 Feb 2013 05:55:35 -0800 (PST)
Lines: 402
Approved: news@gmane.org
Message-ID: <c15b7b1c-6d6f-4472-8a43-b2fb374b92a1@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_7_19754698.1360590935717"
X-Trace: ger.gmane.org 1360590944 28390 80.91.229.3 (11 Feb 2013 13:55:44 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 11 Feb 2013 13:55:44 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCJN7V7TRQMBBYHQ4OEAKGQEN6TEIZY@isocpp.org Mon Feb 11 14:56:06 2013
Return-path: <std-proposals+bncBCJN7V7TRQMBBYHQ4OEAKGQEN6TEIZY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ia0-f200.google.com ([209.85.210.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCJN7V7TRQMBBYHQ4OEAKGQEN6TEIZY@isocpp.org>)
	id 1U4trZ-0007Z9-6x
	for gclcip-std-proposals@m.gmane.org; Mon, 11 Feb 2013 14:56:05 +0100
Original-Received: by mail-ia0-f200.google.com with SMTP id o25sf14680170iad.7
        for <gclcip-std-proposals@m.gmane.org>; Mon, 11 Feb 2013 05:55:45 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-received:x-beenthere:x-received:date:from:to:message-id:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-google-group-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=DwqR8/P7srP8NjfHsnpbsOu1JIK3w1QkQxlGc9JoPyQ=;
        b=O9spPvgBt1yO/z+hvqA+nEXiA/eMapHCPcM12fehFqDobSrJfu3UZYb1DmJzViu5c6
         5PPBBgbA/lsTrAz3HCN/DjjlauLw58xVjiO+gaZHyeqkLyuJHgtnD06qFUX+lnMOQWyV
         dntGPsXsvJveaNZQglVJTLOcoeCaH4dnbJ7FlbWzOLBbabp2ddEfkTuMBSV0oBQd3AjP
         shmeYAD9e+dpWmTrJARBOmV/Hjxyw1Qx7HEL9uz+hbg+ZuLzs3S/2veIuyfPZyDbFjXI
         wUhCcdn7GZvQiVY36yVvxmSoepQ53vFgMUG8mvokZ6+cfb8qbp3cmBrPTxWfoojMVX71
         e0DA==
X-Received: by 10.42.96.1 with SMTP id h1mr10816578icn.9.1360590944624;
        Mon, 11 Feb 2013 05:55:44 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.179.72 with SMTP id de8ls1652142igc.9.gmail; Mon, 11 Feb
 2013 05:55:37 -0800 (PST)
X-Received: by 10.50.149.132 with SMTP id ua4mr288843igb.8.1360590937147;
        Mon, 11 Feb 2013 05:55:37 -0800 (PST)
X-Original-Sender: ricardofabianodeandrade@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:2808
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/2808>

------=_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=
&nbsp;<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>&nbsp;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&nbsp;of a gi=
ven&nbsp;enumerator's index (or order, or position) and its&nbsp;<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&nbsp;syntax&nbsp;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">]&lt;</span><span style=3D"color:=
 #606;" class=3D"styled-by-prettify">AnEnum</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&gt;();</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">]&lt;</span><=
span style=3D"color: #606;" class=3D"styled-by-prettify">AnEnum</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</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&nbsp;during compi=
le-time&nbsp;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]&lt;AnEnum&gt;(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;">&nbsp;pseudo-inheritan=
ce and/or&nbsp;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">]&lt;</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">AnEnum</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&gt;([</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">]&lt;</span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">AnEnum</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&gt;()</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=
&lt;AnEnum&gt;() 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">&lt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">[</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">magic</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">]&lt;</span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>AnEnum</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt=
;();</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">]&lt;</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">AnEnum</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&gt;(</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">&lt;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">&gt;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>class enum_=
index<br>{<br>&nbsp; &nbsp; vector</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">&lt;AnEnum&gt;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> values;<br>&nbsp; &nbsp; enum_index() {<br>&nb=
sp; &nbsp; &nbsp; &nbsp; values.resize([magic]</span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">&lt;T&gt;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">());<br>&nbsp; &nbsp; &nbsp; &nbsp; for(=
size_t i =3D 0; i &lt; [magic]</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">&lt;AnEnum&gt;</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">&lt;AnEnum&gt;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">(i); }<br>&nbsp; &nbsp; }<br>&n=
bsp; &nbsp; size_t index(const T&amp; value) const<br>&nbsp; &nbsp; { 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">&lt;AnEnum&gt;</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>&nbsp;</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&nbsp;<font face=3D"courier new, monospace">sizeof</font> and <=
font face=3D"courier new, monospace">typeid</font>&nbsp;(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>&nbsp;</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&nbsp;to&nbsp;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&nbsp;maintainability&nbsp;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 />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to 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 />
&nbsp;<br />
&nbsp;<br />

------=_Part_7_19754698.1360590935717--

.
