220 27959 <1472202710.17129.25.camel@bsdforen.de> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Dominic Fandrey <kamikaze@bsdforen.de>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Make (strongly typed) enums castable to char
 const * const
Date: Fri, 26 Aug 2016 11:11:50 +0200
Lines: 83
Approved: news@gmane.org
Message-ID: <1472202710.17129.25.camel@bsdforen.de>
References: <1472132849.17129.9.camel@bsdforen.de>
	 <e585a9d9-c120-48a9-9ab7-2cbfbc206038@isocpp.org>
	 <CACGiwhG3EF5_+Ytu9k3h8gtYdmLCkkA0e109u2RfmPtForNMcA@mail.gmail.com>
	 <1472148645.17129.15.camel@bsdforen.de>
	 <CANh-dXmhWtTBeEwBheNOApVwiCkMB6Hwqg8n+xjt5aMvoW+pbg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1472202720 26512 195.159.176.226 (26 Aug 2016 09:12:00 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 26 Aug 2016 09:12:00 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCPM3OG72QHBBWMPQC7AKGQE4JECEQY@isocpp.org Fri Aug 26 11:11:55 2016
Return-path: <std-proposals+bncBCPM3OG72QHBBWMPQC7AKGQE4JECEQY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f69.google.com ([209.85.215.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCPM3OG72QHBBWMPQC7AKGQE4JECEQY@isocpp.org>)
	id 1bdDB3-0006R7-Gx
	for gclcip-std-proposals@m.gmane.org; Fri, 26 Aug 2016 11:11:53 +0200
Original-Received: by mail-lf0-f69.google.com with SMTP id k135sf48659576lfb.2
        for <gclcip-std-proposals@m.gmane.org>; Fri, 26 Aug 2016 02:11:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=message-id:subject:from:to:date:in-reply-to:references:mime-version
         :content-transfer-encoding:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=XkUJSZxINNrqD3JDQrBF4at8/hqHINF8l37Yzd9PC6Q=;
        b=h9zeZP6e2BSuFZw0tHGhi+QAltspcUoRXFyBnK737zWhIjPXIIXGsYcV11HP937goS
         wvRrKgns8O4SQ+MkfcAja94XjSLL62ranOrqzEj4PFNwytPqZr4awqdb53l0oUEE4non
         fJ/8iwROwGDylKe7Rr1LAl8Il94VtLLxMeGJtGnkNIqxLnAvl5ogi1r6rZJ/7viQN3DQ
         0Kzq/+JQzCqt9dOjCd6ex3PZUeXu+d5U2Qgd4jvTz+iP+lTGlbbQGPOq3zroI/XmKteH
         cWBWvx8XP7oPqB3lDnPHCYnyNYxRq2Js7hSQBu2EhM6+3J4xdSvr5yczFQT2mUGa+231
         es8g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to
         :references:mime-version:content-transfer-encoding:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=XkUJSZxINNrqD3JDQrBF4at8/hqHINF8l37Yzd9PC6Q=;
        b=VElnn0L/54tu+RTkY1nSfae+dYJCGpccmrsPl2O9oYV6oZtKR1qKHfWoJoGMsjugQ8
         z7PBhW8LAP/GB7zipvjN+coChzo6XXD7WmEmwMiehG0/aqGqfLdZIVjkcyhf5Cuaja7l
         FosSWl1E+l5khtCEXK7zPU+7PfL7A6nfnixJ8NCPly1eXkrvexT26+xtZQtdFgylSQBY
         EtyAy9d8i4shkw8PrgmncF6pZgjNXOP6QZKkDSk94RD4LThz+vhquCdZIYzJ5hYX4DFa
         3A/sl4xCLRf/Kg33lPLg0XiY3xc+lxorpdHuzNaadoLQqoSbBQOFrOGKzVq71ndDoM0b
         Wrt 
X-Gm-Message-State: AE9vXwN4s1SWH0dA9EryTKAXBDheIIyTWDx/vryL6ywkmNI7qlzmiGSiAhzeMrpKHOiUUA==
X-Received: by 10.28.199.6 with SMTP id x6mr389933wmf.2.1472202714557;
        Fri, 26 Aug 2016 02:11:54 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.46.5.22 with SMTP id 22ls162017ljf.36.gmail; Fri, 26 Aug 2016
 02:11:52 -0700 (PDT)
X-Received: by 10.25.205.200 with SMTP id d191mr679213lfg.212.1472202712818;
        Fri, 26 Aug 2016 02:11:52 -0700 (PDT)
Original-Received: from bsdforen.de (bsdforen.de. [82.193.243.81])
        by mx.google.com with ESMTP id r192si8034018lfr.2.2016.08.26.02.11.52
        for <std-proposals@isocpp.org>;
        Fri, 26 Aug 2016 02:11:52 -0700 (PDT)
Received-SPF: pass (google.com: best guess record for domain of kamikaze@bsdforen.de designates 82.193.243.81 as permitted sender) client-ip=82.193.243.81;
Original-Received: from localhost (iz-aix-213a.HS-Karlsruhe.DE [193.196.64.213])
	(using TLSv1 with cipher AES256-SHA (256/256 bits))
	(No client certificate requested)
	by bsdforen.de (Postfix) with ESMTPSA id 0F93E3989FA
	for <std-proposals@isocpp.org>; Fri, 26 Aug 2016 11:11:50 +0200 (CEST)
In-Reply-To: <CANh-dXmhWtTBeEwBheNOApVwiCkMB6Hwqg8n+xjt5aMvoW+pbg@mail.gmail.com>
X-Mailer: Evolution 3.18.5.1 FreeBSD GNOME Team Port
X-Original-Sender: kamikaze@bsdforen.de
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 best guess record for domain of kamikaze@bsdforen.de designates 82.193.243.81
 as permitted sender) smtp.mailfrom=kamikaze@bsdforen.de
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:27959
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/27959>

On Thu, 2016-08-25 at 11:39 -0700, 'Jeffrey Yasskin' via ISO C++ Standard -=
 Future Proposals wrote:
> On Thu, Aug 25, 2016 at 11:10 AM, Dominic Fandrey <kamikaze@bsdforen.de>
> wrote:
>=20
> >=20
> > On Thu, 2016-08-25 at 16:55 +0100, D. B. wrote:
> > >=20
> > > On Thu, Aug 25, 2016 at 4:17 PM, Derek Ross <antiquarktv@gmail.com>
> > wrote:
> > >=20
> > >=20
> > > >=20
> > > >=20
> > > > Note that enums can have duplicate values, which throws a wrench in=
to
> > the
> > >=20
> > > >=20
> > > > reflection works.=C2=A0=C2=A0E.g.:
> > > >=20
> > > > enum class FooBar { KEKS =3D 2, DOSE =3D 2 };
> > > >=20
> > > > What will the result be for:
> > > >=20
> > > > FooBar fb =3D FooBar::KEKS;
> > > > cout << static_cast<char const*>(fb) ;
> > > >=20
> > > that only "throws a wrench into the reflection works" as proposed by =
the
> > > OP, by no means generally. the WG proposal linked (A) would not suppo=
rt
> > > this because it is static and (B) has presumably already accounted fo=
r
> > such
> > >=20
> > > possibilities and effortlessly gets around them with compile-time
> > > wizardry... again, *presumably.*
> > >=20
> > It's not really useful for what I'm doing if it's not runtime capable.
> >=20
> > For multiple mentions I'd just leave it implementation defined or
> > establish a simple first definition rule.
> >=20
> > I am assuming that in most cases overlapping definitions are aliases:
> >=20
> > =C2=A0=C2=A0=C2=A0=C2=A0enum class Flags { NONE =3D 0, COMPATIBLE =3D 1=
, COMPAT =3D 1, EXPERIMENTAL
> > =3D 2 };
> >=20
> The static reflection proposal lets you iterate at compile time over all
> the enum values inside an enumeration, which lets you write a generic
> library function to do what you want. That function will have to pick an
> answer to FlagsString(1), and we're hoping that some libraries appear to
> show us some options before we put a choice into the standard library.

That sounds fine to me, I prefer a generic approach over my limited
proposal. I guess it wouldn't be too difficult to build a nested type
containing the string and the enum value and a constexpr function
template that iterates through the type and returns the string for the
first enum match.

You could also build one that would return "COMPATIBLE|EXPERIMENTAL"
for Flags{3}, for enums that only have powers of two values. But that
would probably result in the creation in n! strings, so it might not
be a great idea (even if n is usually limited to 64).

--=20
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?


--=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/1472202710.17129.25.camel%40bsdforen.de.

.
