220 27984 <a057117d-4d32-4f39-ac2b-ada996a75ec3@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: szollosi.lorand@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Make (strongly typed) enums castable to char
 const * const
Date: Fri, 26 Aug 2016 16:30:56 -0700 (PDT)
Lines: 139
Approved: news@gmane.org
Message-ID: <a057117d-4d32-4f39-ac2b-ada996a75ec3@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_2302_750984371.1472254257014"
X-Trace: blaine.gmane.org 1472254263 4839 195.159.176.226 (26 Aug 2016 23:31:03 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 26 Aug 2016 23:31:03 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDR7PROGSALRBMVCQO7AKGQEZ7DTTYQ@isocpp.org Sat Aug 27 01:30:59 2016
Return-path: <std-proposals+bncBDR7PROGSALRBMVCQO7AKGQEZ7DTTYQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pf0-f198.google.com ([209.85.192.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDR7PROGSALRBMVCQO7AKGQEZ7DTTYQ@isocpp.org>)
	id 1bdQaQ-0000ku-My
	for gclcip-std-proposals@m.gmane.org; Sat, 27 Aug 2016 01:30:58 +0200
Original-Received: by mail-pf0-f198.google.com with SMTP id 63sf175866768pfx.0
        for <gclcip-std-proposals@m.gmane.org>; Fri, 26 Aug 2016 16:30:59 -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=ajsfFO/DGH+41Z0V1OX8yQZknoUzJ4Wngpa2H/cB0aI=;
        b=HKY/KEVvaKEQKbZovTCme/xMWKQNVQj2qMukZ5zf1AehAzh+TPAqzw2VeIVjcmnyqj
         Fchv6B6ik8i9Yh9/GPhs3PEylU/iK4mmqd2Q7Ntze3jxe6TDBrityQ5o656039WlSTBr
         oxfQ9BEF8a88725tM3CBud0Rjb7VBqvlZFwcqkrBzHmUP/Ee0eQm47P6p7y4s/+YycNg
         uo8pFp3VRGICw0ft11NAi46fQiyr6usKGXUD+gvWo+XUBDJEdX11ljSFJKHo4ybwpgS6
         PMQaTqcvtVbencgAxN/cJej3Wb4/R4t+v3m3VLnXDd0Y60QWZR6pfwkW41dikvNLEtId
         h1iw==
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=ajsfFO/DGH+41Z0V1OX8yQZknoUzJ4Wngpa2H/cB0aI=;
        b=1B6a1LAfmPVqhfHwzLbIq1nxVPpdChjuO25hFeaaCGhIXZe1CoxFiDZ+hpQOSThetg
         VgLbejJ9/Q5Pj3r4/i2W4v5oqqVI+htgAIYVRmXHHXeTr4N+egQDQt/u9ZAI9y815OPX
         PSzut1RhaHkWAO0cNj7h42ckWhEkKG0CIPBo+2oQuhEQ8KPLT5NyVNp3zT+gjj1jWqpa
         mX8lX3LbVnCPFybqZF1D9s2MbXxhD28ikie7ypabVlL0ich5zDzoY8EFFSCEB5d7VsW2
         w7DLqO9M7tPzw3UAlQviXIi6Bu2wDPeA6jGyf0QPKW4dAeggxqtPH9BpDCl0MxsRczAo
         7GKg==
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=ajsfFO/DGH+41Z0V1OX8yQZknoUzJ4Wngpa2H/cB0aI=;
        b=KHuU97h+H/c2YTHY9Wno/fzIyFh5OcW/l4c+6lyjbHoZT08G05thGRGEDjmPRu8SNu
         RGiaamJtYpePpD6cr8+19XRrPLOyyCdTp74AOWYJlw3hwhxPaZWiKGGLUWgLvHoYH4cP
         N/FQo1nGACL9wcZxApp9j9bbdmzYcreHOlYpKkO2xnq2wk8IdW8TUZbGnpmWhvuoBT7q
         /dHqXahTAdrdX6SQ//X1jJl7GoaElSNAIzDqi/tb2BYUFyiuTeAmxdb/z3QHX3LWwoQD
         ioQENfIzgXoUA2ZJJ7Wa50boI6IY5BHRLVri3QK3Q1VRHzTlVPBbNFjxjLsd0WQKgnAP
         wTDg==
X-Gm-Message-State: AE9vXwNGhVx0T6wMMVyn9iZm93/B4bw9R3451MKt6Z8tRSzM6Ah37S+jg2WNur7cBeKS+w==
X-Received: by 10.66.170.208 with SMTP id ao16mr4611048pac.9.1472254259169;
        Fri, 26 Aug 2016 16:30:59 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.200.85 with SMTP id y82ls1710766iof.24.gmail; Fri, 26 Aug
 2016 16:30:58 -0700 (PDT)
X-Received: by 10.36.239.3 with SMTP id i3mr103048ith.2.1472254258001;
        Fri, 26 Aug 2016 16:30:58 -0700 (PDT)
In-Reply-To: <1472132849.17129.9.camel@bsdforen.de>
X-Original-Sender: szollosi.lorand@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:27984
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/27984>

------=_Part_2302_750984371.1472254257014
Content-Type: multipart/alternative; 
	boundary="----=_Part_2303_989579670.1472254257014"

------=_Part_2303_989579670.1472254257014
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi,

I hate to troll in (esp. since I'm top-posting :) ), but you know that you=
=20
can achieve this using macro-metaprogrammed FOREACH(); or, if you're okay=
=20
with uintptr_t values and don't care about enum values, you can use string=
=20
addresses (when you put strings in a struct using a macro), which is way=20
more readable?

Regards,
-lorro

2016. augusztus 25., cs=C3=BCt=C3=B6rt=C3=B6k 15:47:34 UTC+2 id=C5=91pontba=
n Kamikaze Dominic=20
Fandrey a k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> I searched this list for similar suggestions, but of course I may=20
> have overlooked something.=20
>
> I frequently use the following pattern:=20
>
>     enum class FooBar { KEKS, DOSE };=20
>     char const * const FooBarStr[]{"KEKS", "DOSE"};=20
>
> I use the strings to in error messages, verbose output, etc.=20
>
>     FooBarStr[static_cast<int>(FooBar::KEKS)] // "KEKS"=20
>
> This has some disadvantages, e.g. enums with explicitly stated values=20
> may have gaps, negative values and may be defined out of order.=20
> Also, changing the enum also means changing the strings manually.=20
>
> What I'd like to see:=20
>
>     static_cast<char const *>(FooBar::KEKS) // "KEKS"=20
>
> I think this would be simple to add to an existing compiler and it's=20
> very unlikely to clash with existing code, because you have to jump=20
> through some hoops to cast a strongly typed enum to a pointer type.=20
>
> --=20
> A: Because it fouls the order in which people normally read text.=20
> Q: Why is top-posting such a bad thing?=20
> A: Top-posting.=20
> Q: What is the most annoying thing on usenet and in e-mail?=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/a057117d-4d32-4f39-ac2b-ada996a75ec3%40isocpp.or=
g.

------=_Part_2303_989579670.1472254257014
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<br><br>I hate to troll in (esp. since I&#39;m top-post=
ing :) ), but you know that you can achieve this using macro-metaprogrammed=
 FOREACH(); or, if you&#39;re okay with uintptr_t values and don&#39;t care=
 about enum values, you can use string addresses (when you put strings in a=
 struct using a macro), which is way more readable?<br><br>Regards,<br>-lor=
ro<br><br>2016. augusztus 25., cs=C3=BCt=C3=B6rt=C3=B6k 15:47:34 UTC+2 id=
=C5=91pontban Kamikaze Dominic Fandrey a k=C3=B6vetkez=C5=91t =C3=ADrta:<bl=
ockquote 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/a057117d-4d32-4f39-ac2b-ada996a75ec3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a057117d-4d32-4f39-ac2b-ada996a75ec3=
%40isocpp.org</a>.<br />

------=_Part_2303_989579670.1472254257014--

------=_Part_2302_750984371.1472254257014--

.
