220 35420 <ouvhb9$odv$1@blaine.gmane.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Bo Persson <bop@gmb.dk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Allow out-of-class operator overloading for enum classes
Date: Mon, 20 Nov 2017 22:27:13 +0100
Lines: 106
Approved: news@gmane.org
Message-ID: <ouvhb9$odv$1@blaine.gmane.org>
References: <b9b24701-fd4e-411b-91e1-608bba06fe96@isocpp.org>
 <608409c3-7708-4024-8ca5-8ecd566ca4a9@isocpp.org>
 <990fd030-20de-4bec-b11f-b43f9338667c@isocpp.org>
 <ouv6bl$hjh$1@blaine.gmane.org>
 <40465af3-4752-44b9-9367-cf2d1c41a335@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1511213246 29635 195.159.176.226 (20 Nov 2017 21:27:26 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 20 Nov 2017 21:27:26 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101
 Thunderbird/52.4.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCZ6RLW3UIKBBP4RZXIAKGQEWKRWCGA@isocpp.org Mon Nov 20 22:27:22 2017
Return-path: <std-proposals+bncBCZ6RLW3UIKBBP4RZXIAKGQEWKRWCGA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f71.google.com ([209.85.215.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCZ6RLW3UIKBBP4RZXIAKGQEWKRWCGA@isocpp.org>)
	id 1eGtb7-0007Sk-Hg
	for gclcip-std-proposals@m.gmane.org; Mon, 20 Nov 2017 22:27:21 +0100
Original-Received: by mail-lf0-f71.google.com with SMTP id 73sf2431978lfu.13
        for <gclcip-std-proposals@m.gmane.org>; Mon, 20 Nov 2017 13:27:29 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1511213249; cv=pass;
        d=google.com; s=arc-20160816;
        b=v436OFI4Vvl+MFiAakElak80rdg18Gr5Cwy76Nol3Y9K5Y+eSrEJj8f5vmUfHbKH1Y
         r41i0Y+ZMJJaAZw/INswyit/bXEtYrDwR7MgaSS4CywvfpTksVsypPkujqauPA/fV86f
         0YgzmOVzpNlYQDCyYNrrudbf0Wl1Ts2hR6c1kJXoj3nMZ9knb/zCA8rxJ9Uv8VIy84Ww
         UhDNHftr3yH+K7mxGaYU9vlu+vS5i+c2xG0hWLDo2u04sHKlM/aYXRN/5rnCdub8chYX
         q3f4BGgRuMOJ5xoU6vSy1pMTNDDOemJLbfDc4SBVNkZ4SjdOqhtEwBqgJHCZMC+upwaG
         ObQg==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:content-language
         :in-reply-to:user-agent:content-transfer-encoding:mime-version
         :references:message-id:lines:date:subject:from:to
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=3N/kj1uMP1eABzQj3oETUeEeoyLXWKbfjwY27KOHxho=;
        b=ab4v2hMRP811oLS1s9UkpO4E3B9wRAHF5Z0Fl8wa2UlI7RF0aqWKTy+RDjhV4tDHd1
         MSzm/NeG6jQwXvWu7KkfvyeZTuEDw+KhYpm7MBk0di3uyCuJf0o+D1NoZF7TvWANGjpc
         Ubj4fAoEicP8MgJ+4m4pGPyczcitzlrFLZxsusxhA+dxyXecMpSb5czN8V8OWO0ZV8Dm
         Vj1/270edgrsp10Nuq4vyWrXW++no8N0FhcR2sCALavpKs6id7VBzi6b1V4b+qMIxunY
         WUelic8+nKrE8cZtjlUEvsKxcqZJ3A6Rjo4skTF5BkVypT 
ARC-Authentication-Results: i=2; mx.google.com;
       spf=neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=to:from:subject:date:lines:message-id:references:mime-version
         :content-transfer-encoding:user-agent:in-reply-to:content-language
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=3N/kj1uMP1eABzQj3oETUeEeoyLXWKbfjwY27KOHxho=;
        b=LKzgxYNgUH4+b3tOWNOKfhyLxmAPZ8dc++klhxfdWL52JaHZruzdPwrzEb4+YS5o6l
         dU07z/Nx3ZsJmqS4c4dZvCgCd/koFkTKYgCeS4pLVVxD1PsfOSySc3+8GxLfUIBci6Wo
         JvYR3YHj7WX1yZg7zxGGjAB/7b28ZoNYbPJJvQYzsQZyAmG3KC6iZsJazmQq3avmUG1Y
         lEInDgCS1itWab2gbiF0HrRKN+LsKbOllylKhnQv+lUF6mxbvPFk8qhf/GRZ5fGUNBBy
         VF+6iDb4rRHxL2ucRO1l1523nBbKOJO0iSXDaoWvV0zJbtqSl8Y21oy6OqkBkBNf1qbR
       
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:to:from:subject:date:lines:message-id:references
         :mime-version:content-transfer-encoding:user-agent:in-reply-to
         :content-language: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=3N/kj1uMP1eABzQj3oETUeEeoyLXWKbfjwY27KOHxho=;
        b=S3Ip2clvS3sN9hbrvrjFsuG8gV0ATjaufq2Km/h+c8dWM0Eq1fDOq5rM7GrdSgIidz
         9nEyKFCQVoguK2zpAhm2T4UEPQyNt821fax5t+Ub/VsW0FlXUNSRll8NLOSc56wXrpV5
         rnF5xGiDughNO1oPyL6oycapWeAo3BHGL4nVovwhW+eNQ1AdCEptafR01lcwwZ+4CRxN
         YQmQXfxjQi0ZutAB54DlmnHJnTTwj9TZlh9p2CvDqzNcaSoHTZ7BLqU9LJHvfCsniwDK
         LuWOmMFDNKyKzBG2ETvsUpYEceZo6lQFEtNgC 
X-Gm-Message-State: AJaThX762L+qWPmM29Nn3642t6pMJJdlYRhob6xr47BWZnCBJ9Rp20pj
	C6XS6e0z5AGbzvj9EBx+9Xo=
X-Google-Smtp-Source: AGs4zMYpeNsFEzVIf1t2RHYRCWDSuxdy8URJj8a8KLKcuGwGjMQRxdjdjA96RnWtvJAJPHfTJw2cHQ==
X-Received: by 10.25.202.4 with SMTP id a4mr417526lfg.32.1511213249095;
        Mon, 20 Nov 2017 13:27:29 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.46.29.73 with SMTP id d70ls1100800ljd.4.gmail; Mon, 20 Nov
 2017 13:27:26 -0800 (PST)
X-Received: by 10.46.84.86 with SMTP id y22mr5196276ljd.89.1511213246868;
        Mon, 20 Nov 2017 13:27:26 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1511213246; cv=none;
        d=google.com; s=arc-20160816;
        b=kAzbqcqPj5y2xo2VmR5pILx6cB7RFFm2dNsJZz/amiJYYusq4mraXFhgT3/VUEQGSa
         Vjx2x1CakGdyMv9yeNkR5ftSz/SU//+w/cSrdkHO2lVK5gnQF/jrw8ZG2MM334PSUklY
         K44ZRXsqVKAh/PoPI9uJeUQBprbiNAcJFZFwvZbp5wo3f9bXbpJ8zJXjfYriwrzGN6lD
         vDD1Q5Y++tRQJb62rkphY/35lPtwk5YzkLISLDmhG5RKSKNmU3dI2HSEfCrYigjNvUYT
         FS4Gm11rm66mDZuxUqRDI9zNdXMr7aQ5mbnFY3w7laoSOPVRHgxma6m/8s0OM26uqIff
         uBTA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-language:in-reply-to:user-agent:content-transfer-encoding
         :mime-version:references:message-id:lines:date:subject:from:to
         :arc-authentication-results;
        bh=Ut+JRI+L7Dd1uLr3nd2we5auH6f9Wnmen1VYzDTW0Xs=;
        b=zeaMur5t3QIjJfLpddP64MKEJYwDbympqVOttIFZDyPGq8COs4TF13Yf3/ILrvfn3K
         LqswfBtqMID87unmLQKywFBPTwOcccc1n0+qUc4kmM5PawVTGfmmsCnXnbpr5x7ZAJsk
         eP7jo3AvRUo0b47hoaasAgmpqPb1olt2oNu2dWXXbEENP9MLAjcjNV4lzyyzAIGXPc8a
         KJ7ZXwjdauzimIkiQrdG8Km2lkGTgg6A2Efpkh7/nOyON9R65eUIGuCHAdGBaZoBzx/J
         fX4Og37jYJIRj/cMeTlpqo0f/KVipimgPOIZ+8BiG822f6/khyOShMegDSyheJzy1sLL
         FNUg==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org
Original-Received: from blaine.gmane.org ([195.159.176.226])
        by mx.google.com with ESMTPS id x1si796273lja.308.2017.11.20.13.27.26
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 20 Nov 2017 13:27:26 -0800 (PST)
Received-SPF: neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) client-ip=195.159.176.226;
Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2)
	(envelope-from <gclcip-std-proposals@m.gmane.org>)
	id 1eGtax-0006u3-IE
	for std-proposals@isocpp.org; Mon, 20 Nov 2017 22:27:11 +0100
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 85
Original-X-Complaints-To: usenet@blaine.gmane.org
In-Reply-To: <40465af3-4752-44b9-9367-cf2d1c41a335@isocpp.org>
Content-Language: sv
X-Original-Sender: gclcip-std-proposals@m.gmane.org
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 195.159.176.226 is neither permitted nor denied by best guess
 record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org
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:35420
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35420>

On 2017-11-20 19:30, Nicol Bolas wrote:
> On Monday, November 20, 2017 at 1:19:55 PM UTC-5, Bo Persson wrote:
>=20
>     On 2017-11-20 18:36, Aar=C3=B3n Bueno Villares wrote:
>      >
>      >
>      > On Monday, 20 November 2017 18:18:36 UTC+1, Nicol Bolas wrote:
>      >
>      >
>      >
>      > =C2=A0 =C2=A0 On Monday, November 20, 2017 at 11:59:03 AM UTC-5, A=
ar=C3=B3n Bueno
>      > =C2=A0 =C2=A0 Villares wrote:
>      >
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 Enum classes doesn't allow, by default=
, implicit
>     conversion, not
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 even to the underlying type:
>      >
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 |
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 enumclassA :int{zero,one };
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 voidfoo(int){}
>      >
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 intmain(){foo(A::zero);}
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 |
>      >
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 and that is a good thing, but sometime=
s, you need a enum
>     class
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 only to avoid name colissions, for exa=
mple:
>      >
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 |
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 enumclasstable1_cols {id,name };
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 enumclasstable2_cols {id,address };
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 |
>      >
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 If table1_cols and table2_cols were ra=
w enums, there
>     would be a
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 colission between both id named values=
, since they have
>     global
>      > =C2=A0 =C2=A0 =C2=A0 =C2=A0 namespace scope,
>      >
>      >
>      > =C2=A0 =C2=A0 If they were unscoped enums, you could /still/ refer=
 to them as
>      > =C2=A0 =C2=A0 `table1_cols::id` and `table2_cols::id`. So just do =
that.
>      >
>      >
>      > It gives you (g++ at least) a compiler error because `id` has been
>      > redeclared.
>      >
>=20
>     So disable that warning, or put the unscoped enum inside its own scop=
e
>     (namespace or struct).
>=20
>     namespace table1_cols { enum {id,name}; };
>=20
>=20
> But then, it's difficult to use them as a typed quantity. That is,=20
> making a variable of type `table1_cols` isn't possible, since it's a=20
> namespace. You'd have to use `decltype` gymnastics.

This was to solve one problem - implicit conversion to ints.

If you want a type name for this, you can name the enum and use that as=20
a type

     namespace table1 { enum cols {id,name}; };

     using table1_cols =3D table1::cols;


>=20
> Personally, I try to design things so that either we're talking about an=
=20
> integer or we aren't. The OP's problem only arises when you have an=20
> enumeration that you sometimes use as an enum and sometimes use as an=20
> integer. I don't think we should make language facilities to facilitate=
=20
> that corner case; we should make it as painful as possible to=20
> /discourage/ design which leads to that.
>

Yes, it is a problem when you use enum class to try to make the type not=20
implicitly convertible to an integer, except sometimes. It is hard to=20
write the code for "implicitly convertible only when I want it to be".


     Bo Persson



--=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/ouvhb9%24odv%241%40blaine.gmane.org.

.
