220 29259 <CANPtknxi-106qkFiGieTUCB9w=yPwjip5-Nbukb2Ko_qZ36qbg@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Peter Koch Larsen <peter.koch.larsen@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: explicit conversion from enum class to its
 underlying type
Date: Sun, 30 Oct 2016 15:33:13 +0100
Lines: 81
Approved: news@gmane.org
Message-ID: <CANPtknxi-106qkFiGieTUCB9w=yPwjip5-Nbukb2Ko_qZ36qbg@mail.gmail.com>
References: <4afed494-4fc5-4b06-b3e7-255aa293068e@isocpp.org>
 <f380095f-96be-d02f-584b-6821f70a20b2@wanadoo.fr> <1c81b80e-33b8-4de3-9bf7-94656e8b98f5@isocpp.org>
 <74d02121-9633-b6d1-1187-2a9ab660089d@wanadoo.fr>
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 1477838024 21285 195.159.176.226 (30 Oct 2016 14:33:44 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 30 Oct 2016 14:33:44 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDRIBXXKZQERBK4J3DAAKGQEKGWBDVA@isocpp.org Sun Oct 30 15:33:40 2016
Return-path: <std-proposals+bncBDRIBXXKZQERBK4J3DAAKGQEKGWBDVA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f71.google.com ([209.85.218.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDRIBXXKZQERBK4J3DAAKGQEKGWBDVA@isocpp.org>)
	id 1c0rAf-0002EV-7s
	for gclcip-std-proposals@m.gmane.org; Sun, 30 Oct 2016 15:33:13 +0100
Original-Received: by mail-oi0-f71.google.com with SMTP id j198sf2006764oih.5
        for <gclcip-std-proposals@m.gmane.org>; Sun, 30 Oct 2016 07:33:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :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=NJEuzse+8zlX/DFbleAfrkVlYiY+y3rPMiMeW9pk5Jw=;
        b=i4+2hKu5YDti6ftedzbPJlLhjdGpRcgX0ccvEQwj4KOUAQJ4PKgBE0fJ1tg9pVsBdX
         XynGV9aXVp4+0q9TYltTFpCSeV28/9W4yFPtgsOziBAHbKfI4ZKsB1tQ8p2b5BH3ruTi
         alXRFDaO6wkuBiZnDXoYB+TX/thdccqa3VpZdqnfsnAyG7Zgxp2IasFfe7bNbAUQ7seK
         5Gv7GlpHfh7WXg/SmjdTvAcBhi5pG+WJoPUhAlgp9g13HRrJQXpPigb3MscMIQpH/UxU
         YK12IAjVT9YNKvcW+IEd606TH1M37XmBVgvUMc4CSMHoRS4EGaooGz33gAQ76Po3Y/Jt
         HpvA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to: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=NJEuzse+8zlX/DFbleAfrkVlYiY+y3rPMiMeW9pk5Jw=;
        b=dH8APiMnwcQP4NbViTWNrUSn/WXFFSE1qvWHPoajN3TFFuT4qmPhj7IT9X4yl2fquF
         IeJypPEWTcnlegPX/uZ7WN39e4Rer7fyINKvpOiYrdfcDSB2JQ9vqGdg8u2gZxTGEiHQ
         UMfPjdKuwPYlsnIhOlnAO1t2j8Ve1V65Xakk9R2sD3iCtAWlekS87ZfWLq/eYOjXMlLx
         2q5AapGJzEcWcZ7Hx0zUXv21o1HLM3ILJ6yoftnU6PrrR7stmcvkPDS6Ht0be8snQy51
         QyslSMS36gxs+x6aQxH5pes0IxwW2IWGMeciIW/ljZuzlMNuWeAou1kbPi5ENRqBvao1
         UkC 
X-Gm-Message-State: ABUngvffnkBoFv9sMnZZYoUxr8KKsQHA2/TKTg57kWNEMBcOOHyQAaqWtaZGRL+E6bsg8g==
X-Received: by 10.157.29.131 with SMTP id y3mr8575371otd.133.1477837995509;
        Sun, 30 Oct 2016 07:33:15 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.40.182 with SMTP id s51ls10833113ota.14.gmail; Sun, 30 Oct
 2016 07:33:14 -0700 (PDT)
X-Received: by 10.176.1.17 with SMTP id 17mr17396572uak.143.1477837994834;
        Sun, 30 Oct 2016 07:33:14 -0700 (PDT)
Original-Received: from mail-vk0-x22c.google.com (mail-vk0-x22c.google.com. [2607:f8b0:400c:c05::22c])
        by mx.google.com with ESMTPS id k3si9887346vkb.112.2016.10.30.07.33.14
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 30 Oct 2016 07:33:14 -0700 (PDT)
Received-SPF: pass (google.com: domain of peter.koch.larsen@gmail.com designates 2607:f8b0:400c:c05::22c as permitted sender) client-ip=2607:f8b0:400c:c05::22c;
Original-Received: by mail-vk0-x22c.google.com with SMTP id y123so88546498vka.3
        for <std-proposals@isocpp.org>; Sun, 30 Oct 2016 07:33:14 -0700 (PDT)
X-Received: by 10.31.156.205 with SMTP id f196mr17824058vke.45.1477837994437;
 Sun, 30 Oct 2016 07:33:14 -0700 (PDT)
Original-Received: by 10.103.70.156 with HTTP; Sun, 30 Oct 2016 07:33:13 -0700 (PDT)
In-Reply-To: <74d02121-9633-b6d1-1187-2a9ab660089d@wanadoo.fr>
X-Original-Sender: peter.koch.larsen@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of
 peter.koch.larsen@gmail.com designates 2607:f8b0:400c:c05::22c as permitted
 sender) smtp.mailfrom=peter.koch.larsen@gmail.com;       dmarc=pass (p=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:29259
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29259>

 I believe bool(e) in that context was a C-style cast.

A small helper function would in my opinion be the best way out for
this purpose.

/Peter

On Sun, Oct 30, 2016 at 2:53 PM, Vicente J. Botet Escriba
<vicente.botet@wanadoo.fr> wrote:
> Le 30/10/2016 =C3=A0 13:20, Nicol Bolas a =C3=A9crit :
>
>
>
> On Sunday, October 30, 2016 at 3:50:18 AM UTC-4, Vicente J. Botet Escriba
> wrote:
>>
>> Le 29/10/2016 =C3=A0 23:51, Andrzej Krzemie=C5=84ski a =C3=A9crit :
>>
>> Hi All,
>>
>> One of the nice safety features of enum classes is that they cannot be
>> implicitly converted to their underlying type. However, do you think we
>> would lose this safety feature if we allowed an explicit conversion to t=
he
>> underlying type?
>>
>> I do not know of any practical use of explicit conversion operators exce=
pt
>> for the contextual conversion to bool. And it is only this conversion th=
at I
>> am interested in.
>>
>>
>> This works already in a non-contextual conversion, isn't it?
>>
>>     bool(e)
>
>
> No, it doesn't. The only way to convert a strongly typed enum to its
> underlying type is with a `static_cast`.
>
>
> It works for clang and gcc
>
> http://melpon.org/wandbox/permlink/TnVrIdj3wz76l7b4
>
> enum class SkipUnused : bool { No, Yes };
>
>         SkipUnused e{};
>         bool b1 {bool(e)}; (void)b1;
>         bool b2 =3Dbool(e); (void)b2;
>         b1 =3D bool(e);
>         if (bool(e))
>             std::cout << "Yes\n";
>         else
>             std::cout << "No\n";
>
> Maybe there is a bug in both compilers ;-)
>
> Vicente
>
> --
> 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/74d02121-963=
3-b6d1-1187-2a9ab660089d%40wanadoo.fr.

--=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/CANPtknxi-106qkFiGieTUCB9w%3DyPwjip5-Nbukb2Ko_qZ=
36qbg%40mail.gmail.com.

.
