220 30480 <58764E08.10000@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: enum_cast proposal
Date: Wed, 11 Jan 2017 10:23:52 -0500
Lines: 49
Approved: news@gmane.org
Message-ID: <58764E08.10000@gmail.com>
References: <efdf2357-00a6-408a-8772-12f99135a880@isocpp.org>
 <57258435-5d82-48e7-8ed7-3c38682418fb@isocpp.org>
 <a35d9f20-9e4f-4789-b7e5-5cb08f99e6bd@isocpp.org>
 <58750288.5080004@gmail.com>
 <e85f0d46-f244-42fe-a276-b4e18b3d627f@isocpp.org>
 <CANPtknwzegDLrDFrMoc5U9Z1y52PBZAC2BtQ=iS6Eur2A6f7NQ@mail.gmail.com>
 <5875286B.7040604@gmail.com>
 <CANPtknxx9BXfwLagcO1ucu4pwi6PS6ewrdPzQsqOXgPUGuR-og@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
X-Trace: blaine.gmane.org 1484148247 27031 195.159.176.226 (11 Jan 2017 15:24:07 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 11 Jan 2017 15:24:07 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.1.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBCU43HBQKGQEMQN4NGY@isocpp.org Wed Jan 11 16:23:57 2017
Return-path: <std-proposals+bncBC37LBFWUIFBBCU43HBQKGQEMQN4NGY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f198.google.com ([209.85.161.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBCU43HBQKGQEMQN4NGY@isocpp.org>)
	id 1cRKkh-0005hH-6J
	for gclcip-std-proposals@m.gmane.org; Wed, 11 Jan 2017 16:23:51 +0100
Original-Received: by mail-yw0-f198.google.com with SMTP id v73sf82394938ywg.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 11 Jan 2017 07:23:56 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to: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=okffxE30YkdyHe7OS4f93G0yo6NGxPb9GOfdfgddlBc=;
        b=Ot4UdfMp/PuqV46K+njLVplUsG9Os0QibQONhRlTd9xJ5BH5TZ9GfGDIuKp3sKO0nz
         JtKXQengbnceDPwxm18U8iguJ5wCPmMFmB9yeA5DOCt5IK9w0fNvnlk9TDlGTImTtQZL
         naPRGFtxMiwqBSEuOj9ajkW7jgcHjuJCX5VKUQ6HNoXA5R33jYtPR6lTijTsIIVHni6q
         hcASUmnraaQWsM38EQhyoWwjDjYZd96+LCGZnrDRrJ+sxCGSM9d5RyOpEbIirv6HSF76
         nfqRmGcjnE7qtuvrPD0Mptf0eUc20gY2BpCC4MnWLqAkmZhnIcq15REc47//P4JMJLlC
         imQQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to: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=okffxE30YkdyHe7OS4f93G0yo6NGxPb9GOfdfgddlBc=;
        b=pBfdqfNQClKavhEHjiZjhubtvLOpz8nfngVtzNAotXMXCY9oW42ZXlaRyUmbN0ZJMZ
         DMK/x72LMz6qoH7DbSR15nAFHSFBRlJIw79hmfWgdzmRpJQRZeYwc9jVbwx+xo/yUxet
         ejPlS/10GZO4ntQCaKZasVrfmtLmCFWcR5qLzi/qFXPQofzCiqjAtzJkIUb5pU7SbRoI
         Wqb0zaXPFHdN+UVDNBJZKkvdxN6lxdJOPyOqQmW/So7k0y0E2o3vo/vNBfKQaqX0tOUl
         ApLCSeX/TKAM6wxVyqYnDqCbw3kNKpdwSY9VDEAa9HGbzq97p455GmTwX3v/4taBI9mA
         sClg==
X-Gm-Message-State: AIkVDXIwdljNzyZbJUafC2KWsC2UioEeYHW7nsR++JQpjhQmW4zHk/KzEaLIarUinjHavw==
X-Received: by 10.129.157.68 with SMTP id u65mr2727191ywg.11.1484148235506;
        Wed, 11 Jan 2017 07:23:55 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.34.211 with SMTP id i202ls1240054ioi.4.gmail; Wed, 11 Jan
 2017 07:23:54 -0800 (PST)
X-Received: by 10.36.20.66 with SMTP id 63mr8471145itg.103.1484148234463;
        Wed, 11 Jan 2017 07:23:54 -0800 (PST)
Original-Received: from mail-it0-x242.google.com (mail-it0-x242.google.com. [2607:f8b0:4001:c0b::242])
        by mx.google.com with ESMTPS id w189si5320355itd.69.2017.01.11.07.23.54
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 11 Jan 2017 07:23:54 -0800 (PST)
Received-SPF: pass (google.com: domain of mwoehlke.floss@gmail.com designates 2607:f8b0:4001:c0b::242 as permitted sender) client-ip=2607:f8b0:4001:c0b::242;
Original-Received: by mail-it0-x242.google.com with SMTP id c20so16367152itb.0
        for <std-proposals@isocpp.org>; Wed, 11 Jan 2017 07:23:54 -0800 (PST)
X-Received: by 10.36.200.68 with SMTP id w65mr5347136itf.85.1484148234097;
        Wed, 11 Jan 2017 07:23:54 -0800 (PST)
Original-Received: from [192.168.1.173] (tripoint.kitware.com. [66.194.253.20])
        by smtp.googlemail.com with ESMTPSA id c9sm3214893ioc.2.2017.01.11.07.23.52
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 11 Jan 2017 07:23:53 -0800 (PST)
In-Reply-To: <CANPtknxx9BXfwLagcO1ucu4pwi6PS6ewrdPzQsqOXgPUGuR-og@mail.gmail.com>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of
 mwoehlke.floss@gmail.com designates 2607:f8b0:4001:c0b::242 as permitted
 sender) smtp.mailfrom=mwoehlke.floss@gmail.com;       dmarc=pass (p=NONE
 sp=NONE dis=NONE) header.from=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:30480
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30480>

On 2017-01-11 02:58, Peter Koch Larsen wrote:
> On Tue, Jan 10, 2017 at 7:31 PM, Matthew Woehlke wrote:
>> On 2017-01-10 12:01, Peter Koch Larsen wrote:
>>> What do you do if you have an enum with some same_valued elements
>>> (enum E { ea = 0, eb = 0})? My implementation forbids this.
>>
>> Why?
>>
>>   E x = ea;
>>   assert(x == eb); // will succeed
>>
>> Such a prohibition makes some sense when converting an enum to a string
>> (or to its ordinal), but there is no problem when converting an int to
>> an enum (or a string to an enum, for that matter).
> 
> This is exactly my problem. I partially use my library in to do this
> stuff, and it could be confusing for the user if you serialize as ea
> and get eb back.

....but you will *also* get `ea` back. The values `ea` and `eb` are not
distinguishable when represented as either the enum nor as an integer
(via value cast). They are only distinguishable as strings or ordinals.

If that isn't what you want, don't give your enum multiple identifiers
with the same value in the first place.

> I also have a bitset class (enum_bitset<Enum>), where
> I as a template parameter define if i set the bit depending on the
> underlying enums ordinal values or by its underlying integral value.
> In neither case do I see any use of having two enums with the same
> value.
> Also, I do not see a reason in have two enums with the same value.

So just *don't do that*. But don't artificially nerf your proposed
feature for people that *do* find that useful.

In your above example, the integer 0 is a member of the set of valid
values of `E`. The cast should succeed. Remember, you aren't changing
the value representation, you're just changing the *type*.

-- 
Matthew

-- 
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/58764E08.10000%40gmail.com.

.
