220 27939 <e585a9d9-c120-48a9-9ab7-2cbfbc206038@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Derek Ross <antiquarktv@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Make (strongly typed) enums castable to char
 const * const
Date: Thu, 25 Aug 2016 08:17:11 -0700 (PDT)
Lines: 172
Approved: news@gmane.org
Message-ID: <e585a9d9-c120-48a9-9ab7-2cbfbc206038@isocpp.org>
References: <1472132849.17129.9.camel@bsdforen.de>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_261_424528993.1472138231816"
X-Trace: blaine.gmane.org 1472138240 2080 195.159.176.226 (25 Aug 2016 15:17:20 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 25 Aug 2016 15:17:20 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDJJ7WHE3YKRB6EX7S6QKGQEZRVKXUA@isocpp.org Thu Aug 25 17:17:16 2016
Return-path: <std-proposals+bncBDJJ7WHE3YKRB6EX7S6QKGQEZRVKXUA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f199.google.com ([209.85.220.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDJJ7WHE3YKRB6EX7S6QKGQEZRVKXUA@isocpp.org>)
	id 1bcwP5-00005I-8x
	for gclcip-std-proposals@m.gmane.org; Thu, 25 Aug 2016 17:17:15 +0200
Original-Received: by mail-qk0-f199.google.com with SMTP id m184sf99773500qkb.2
        for <gclcip-std-proposals@m.gmane.org>; Thu, 25 Aug 2016 08:17:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=mN1C+TRugkjgKHGYNqj7J+eke7rWhzhiXHNFFWYgQFw=;
        b=nlEjMJNyHG7/jStcpufm84CDBaXhNhBk2oqSDxt4vapZ5VIJmhkfUcl/4qt/WDeM/b
         JN+/ZyGp7CBSIR8EKMsmDdkPr0uIsRavizIaQq22suEaLHpPS3JKWTMiFu5S4jwzwX/J
         qQEgx8FupCCbBK+YMoU9TqYMwY00TO+UM7twGgzge0CvfrOwEtQA6eYZeqb5ELkwjEnc
         ZTHSny/FGx6KbhoY5uVX950pT/jvGAQo0ySkn6JLMmxvtd8XQ6v5ljx0uDMp1gripsdH
         OOvkjgZgQAhy7UV2GT9wo4weSQRcRzsTcuhQF0JKu3sGNWjScvZ1HHbcINXtGvX4DMnA
         hxrA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=mN1C+TRugkjgKHGYNqj7J+eke7rWhzhiXHNFFWYgQFw=;
        b=WIsZh1dvwTdKz92OcGs880VelOa7P9NLtxsQ8m217R+xqztqfi/C4gNWCGf3xlEfuj
         PjQVjVE8BD65Fyh/ghfrwQ2XmFjJ6U60ACH6jhtF4QJTBVEXiVNDOhSXgC6LvpZMg9Lo
         V6oBk2P9g868Y7OA0fn7Dbavl2P2sddlvyZbu+vsHh/ZuHcxWZ9b3XhtfQeRMgG81tqm
         6K0/IAYOWeNzeCW6aqMX/wGjGUWMzf0S/rwMaw1dsixGEvZo0OJYasKMzm7SrWppwji1
         N7MtHZCy8tw+UCJruXv5n48nQM6MH0C12ZBaZ0ajI/aom9B9ob8eFTnm4B7X0oaJaZwq
         Hp7Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=mN1C+TRugkjgKHGYNqj7J+eke7rWhzhiXHNFFWYgQFw=;
        b=XzRJOQXa481n/kn5OxZEMmK+qb93NKjzfkC+pwMJJXJaeno2I1C5rS3PXC7ohNPWjx
         ejtEeJqPf32JYepD4jGCOUgJBG5hQTpaiPm9JQtRG9vz6SGHjW6NkAjhgSWw7JSmijCn
         Ve809R7ln5kVtO+deuyC3K/8RSTNqQcqEOp8IyhmE7viYyVvz/xiNGqpKr2nT9yMTCp6
         Bvpnuf1m524cXEAJHUnYy+DwVSNSItndzcM67POkxjdqjBITqlNMW2mXN7YHN8mmPdx6
         /YoXK1PVk22XSbBtF3nenc/RN3n2g5cxWArjKAEPFc3ut/NFmeju7OloLwGtR4VgWJfs
         evgA==
X-Gm-Message-State: AEkoouuzUTEuNyhi7B5KQAgj1HkhnOPDPL+uqlwK3hmuzpCNMkdZMRtq22hz0hjnUiqXYQ==
X-Received: by 10.31.50.72 with SMTP id y69mr6246490vky.13.1472138235937;
        Thu, 25 Aug 2016 08:17:15 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.133.30 with SMTP id h30ls506321iod.20.gmail; Thu, 25 Aug
 2016 08:17:12 -0700 (PDT)
X-Received: by 10.36.227.207 with SMTP id d198mr240290ith.4.1472138232706;
        Thu, 25 Aug 2016 08:17:12 -0700 (PDT)
In-Reply-To: <1472132849.17129.9.camel@bsdforen.de>
X-Original-Sender: antiquarktv@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:27939
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/27939>

------=_Part_261_424528993.1472138231816
Content-Type: multipart/alternative; 
	boundary="----=_Part_262_1782411998.1472138231816"

------=_Part_262_1782411998.1472138231816
Content-Type: text/plain; charset=UTF-8

Note that enums can have duplicate values, which throws a wrench into the 
reflection works.  E.g.:

enum class FooBar { KEKS = 2, DOSE = 2 }; 

What will the result be for:

FooBar fb = FooBar::KEKS;
cout << static_cast<char const*>(fb) ;




On Thursday, August 25, 2016 at 8:47:34 AM UTC-5, Kamikaze Dominic Fandrey 
wrote:
>
> I searched this list for similar suggestions, but of course I may 
> have overlooked something. 
>
> I frequently use the following pattern: 
>
>     enum class FooBar { KEKS, DOSE }; 
>     char const * const FooBarStr[]{"KEKS", "DOSE"}; 
>
> I use the strings to in error messages, verbose output, etc. 
>
>     FooBarStr[static_cast<int>(FooBar::KEKS)] // "KEKS" 
>
> This has some disadvantages, e.g. enums with explicitly stated values 
> may have gaps, negative values and may be defined out of order. 
> Also, changing the enum also means changing the strings manually. 
>
> What I'd like to see: 
>
>     static_cast<char const *>(FooBar::KEKS) // "KEKS" 
>
> I think this would be simple to add to an existing compiler and it's 
> very unlikely to clash with existing code, because you have to jump 
> through some hoops to cast a strongly typed enum to a pointer type. 
>
> -- 
> A: Because it fouls the order in which people normally read text. 
> Q: Why is top-posting such a bad thing? 
> A: Top-posting. 
> Q: What is the most annoying thing on usenet and in e-mail? 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/e585a9d9-c120-48a9-9ab7-2cbfbc206038%40isocpp.org.

------=_Part_262_1782411998.1472138231816
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Note that enums can have duplicate values, which throws a =
wrench into the reflection works.=C2=A0 E.g.:<br><br><div class=3D"prettypr=
int" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, =
187, 187); border-style: solid; border-width: 1px; word-wrap: break-word;">=
<code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">enum</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cla=
ss=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-b=
y-prettify">FooBar</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> KEKS </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">2</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> DOSE </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-p=
rettify">2</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></div></c=
ode></div><br>What will the result be for:<br><br><div class=3D"prettyprint=
" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187=
, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #606;" class=3D"styled-by-prettify">FooBar</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> fb </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-b=
y-prettify">FooBar</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
KEKS</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>cout </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">static_cast</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">const</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*&gt;(</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">fb</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: #660;" class=3D"styled-by-prettify">;</spa=
n></div></code></div><br><br><br><br>On Thursday, August 25, 2016 at 8:47:3=
4 AM UTC-5, Kamikaze Dominic Fandrey wrote:<blockquote class=3D"gmail_quote=
" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding=
-left: 1ex;">I searched this list for similar suggestions, but of course I =
may
<br>have overlooked something.
<br>
<br>I frequently use the following pattern:
<br>
<br>=C2=A0 =C2=A0 enum class FooBar { KEKS, DOSE };
<br>=C2=A0 =C2=A0 char const * const FooBarStr[]{&quot;KEKS&quot;, &quot;DO=
SE&quot;};
<br>
<br>I use the strings to in error messages, verbose output, etc.
<br>
<br>=C2=A0 =C2=A0 FooBarStr[static_cast&lt;int&gt;(<wbr>FooBar::KEKS)] // &=
quot;KEKS&quot;
<br>
<br>This has some disadvantages, e.g. enums with explicitly stated values
<br>may have gaps, negative values and may be defined out of order.
<br>Also, changing the enum also means changing the strings manually.
<br>
<br>What I&#39;d like to see:
<br>
<br>=C2=A0 =C2=A0 static_cast&lt;char const *&gt;(FooBar::KEKS) // &quot;KE=
KS&quot;
<br>
<br>I think this would be simple to add to an existing compiler and it&#39;=
s
<br>very unlikely to clash with existing code, because you have to jump
<br>through some hoops to cast a strongly typed enum to a pointer type.
<br>
<br>--=20
<br>A: Because it fouls the order in which people normally read text.
<br>Q: Why is top-posting such a bad thing?
<br>A: Top-posting.
<br>Q: What is the most annoying thing on usenet and in e-mail?
<br>
<br>
<br></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/e585a9d9-c120-48a9-9ab7-2cbfbc206038%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e585a9d9-c120-48a9-9ab7-2cbfbc206038=
%40isocpp.org</a>.<br />

------=_Part_262_1782411998.1472138231816--

------=_Part_261_424528993.1472138231816--

.
