220 29258 <dc9396b6-00c6-4249-8988-a36f41c52519@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@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 07:23:08 -0700 (PDT)
Lines: 148
Approved: news@gmane.org
Message-ID: <dc9396b6-00c6-4249-8988-a36f41c52519@isocpp.org>
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: multipart/mixed; 
	boundary="----=_Part_1520_927821942.1477837388206"
X-Trace: blaine.gmane.org 1477837411 30744 195.159.176.226 (30 Oct 2016 14:23:31 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 30 Oct 2016 14:23:31 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBTEE3DAAKGQEQOZVS6I@isocpp.org Sun Oct 30 15:23:26 2016
Return-path: <std-proposals+bncBCEKFTV6ZUMBBTEE3DAAKGQEQOZVS6I@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+bncBCEKFTV6ZUMBBTEE3DAAKGQEQOZVS6I@isocpp.org>)
	id 1c0r0s-000510-Np
	for gclcip-std-proposals@m.gmane.org; Sun, 30 Oct 2016 15:23:06 +0100
Original-Received: by mail-oi0-f71.google.com with SMTP id y2sf54252588oie.3
        for <gclcip-std-proposals@m.gmane.org>; Sun, 30 Oct 2016 07:23:09 -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=s8mge/9R4ShGpeeouMMb1RbfB9M4yvyLsEe005NBRis=;
        b=Q4fvty1e/oFStx/BQeSqkCAQdfWgwY4o4neuAtXP6qd6xycTUCDIIebZL/u1EuLfMC
         xYDHlx3QR2qRu9SQU8/rZaFH90+j8myMPB2mrPyNczEjM9nMx1l7dnUsIYV8LcZALxr4
         z6hxOe54g4h5jWqNCJt+GCZha1abQ/Vy307VBwhcXgwt7fgjEpBr26ISts2waDflIi5g
         a08dfDK0Pn/aUrgHgLjXjRxr2bm256XAzp5bdNdBafvfj1y3qhTUbnKqsWU5avfItP81
         KjKz21Ilv/GubEbqkSNDTNmiPFxO0MMjOZkbChTHpNbX7gsy1UvfCwjRvekCpfY8hXje
         iLqg==
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=s8mge/9R4ShGpeeouMMb1RbfB9M4yvyLsEe005NBRis=;
        b=ok4mfpZU66Yn7n5Zt1OpSjmHiPzPG+USHUIbErubjWZcQt1mTm+IXgKtXmXjLKVYWf
         jN7sDUgDFaWKkKX9NzVcQtZy7bwAhbKdk+vaNxdJ9mr/rGXzIjZswJSQmsdT3rMGnUSG
         hHNyRbjwBcRif2QcaZGrrVXdwM7+5xvvj7b7BNptsxpXxY2Nl7NnO/0qrDHk2Ufjc7oB
         m3yK1YMy8CdxZ17RtsyTmeJ29l4nME4kSh8GNgRMD8+xFMpd2ROU1nAO2loI+JHTPOcu
         dU2Bz+q0UcIgL7JVcR0So3Gcqnfyv7NZfaarifwHBMInJwkcYFrn5e+BFB2fF6HZncOj
         EC4Q==
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=s8mge/9R4ShGpeeouMMb1RbfB9M4yvyLsEe005NBRis=;
        b=Be3Ic5TknB0Tk+iILCFJCHaSTyYBUDQan2gL/ZQKZYr1sHFefE2N7sectZ8wFSJ/Ym
         dzwQSk1Mdy/gBdlisN8kIaIEFUWk9XaaTNxHeENvmOM0juadYFoXwuAN2WhwMtHssKDM
         gMuhBozhmDIClyYbjO5ay9aLI5Da9BtWZcjtvN01MW7OXhoSHFWRsoxJGDRQmAn0i0dx
         Sg+tk9CLYPk3CQyj0xRcfAP6qxQid+x284L8BUIzVSRkQTa/+qQRKS9xb0uG1Ok5fkuV
         GOtJG34tiRS01rTQ7Jo35Iks0fsOwogdywTxDCqXajC9J6mqXhaXeo2i9Ii+aiQsUWrG
         x+ZA==
X-Gm-Message-State: ABUngvdAX+GesLSSwwXmd+4tVz5U8Ww5Xd3A7Fvj0cjNkXthR54od8xD1SnY9N8cfuOkvA==
X-Received: by 10.157.13.163 with SMTP id 32mr7963709ots.11.1477837389246;
        Sun, 30 Oct 2016 07:23:09 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.4.101 with SMTP id 92ls6207181otc.28.gmail; Sun, 30 Oct
 2016 07:23:08 -0700 (PDT)
X-Received: by 10.157.17.167 with SMTP id v36mr297158otf.12.1477837388551;
        Sun, 30 Oct 2016 07:23:08 -0700 (PDT)
In-Reply-To: <74d02121-9633-b6d1-1187-2a9ab660089d@wanadoo.fr>
X-Original-Sender: jmckesson@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:29258
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29258>

------=_Part_1520_927821942.1477837388206
Content-Type: multipart/alternative; 
	boundary="----=_Part_1521_1776317284.1477837388206"

------=_Part_1521_1776317284.1477837388206
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Sunday, October 30, 2016 at 9:53:41 AM UTC-4, Vicente J. Botet Escriba=
=20
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=
=20
> wrote:=20
>>
>> 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=
=20
>> implicitly converted to their underlying type. However, do you think we=
=20
>> would lose this safety feature if we allowed an explicit conversion to t=
he=20
>> underlying type?
>>
>> I do not know of any practical use of explicit conversion operators=20
>> except for the contextual conversion to bool. And it is only this=20
>> conversion that 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=20
> underlying type is with a `static_cast`.
>
>
> It works for clang and gcc
>

So why doesn't it work when you use direct initialization of a variable=20
<http://ideone.com/hrMiy7> (like `bool b{e}`)? Direct initialization and=20
creating a temporary ought to work identically.

So if this is an issue, then I would say that the issue is the asymmetry=20
between direct initialization of enum classes and creating prvalues of them=
..

--=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/dc9396b6-00c6-4249-8988-a36f41c52519%40isocpp.or=
g.

------=_Part_1521_1776317284.1477837388206
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Sunday, October 30, 2016 at 9:53:41 AM UTC-4, Vicente J=
.. Botet Escriba wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div>Le 30/10/2016 =C3=A0 13:20, Nicol Bolas a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote type=3D"cite">
      <div dir=3D"ltr"><br>
        <br>
        On Sunday, October 30, 2016 at 3:50:18 AM UTC-4, Vicente J.
        Botet Escriba wrote:
        <blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex">
          <div bgcolor=3D"#FFFFFF" text=3D"#000000">
            <div>Le 29/10/2016 =C3=A0 23:51, Andrzej Krzemie=C5=84ski a =C3=
=A9crit=C2=A0:<br>
            </div>
            <blockquote type=3D"cite">
              <div dir=3D"ltr">Hi All,<br>
                <br>
                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 the
                underlying type?<br>
                <br>
                I do not know of any practical use of explicit
                conversion operators except for the contextual
                conversion to bool. And it is only this conversion that
                I am interested in.<br>
              </div>
            </blockquote>
            <br>
            This works already in a non-contextual conversion, isn&#39;t it=
?<br>
            <br>
            =C2=A0=C2=A0=C2=A0 bool(e)<br>
          </div>
        </blockquote>
        <div><br>
          No, it doesn&#39;t. The only way to convert a strongly typed enum
          to its underlying type is with a `static_cast`.<br>
        </div>
      </div>
    </blockquote>
    <br>
    It works for clang and gcc<br></div></blockquote><div><br>So why doesn&=
#39;t it work when you <a href=3D"http://ideone.com/hrMiy7">use direct init=
ialization of a variable</a> (like `bool b{e}`)? Direct initialization and =
creating a temporary ought to work identically.<br><br>So if this is an iss=
ue, then I would say that the issue is the asymmetry between direct initial=
ization of enum classes and creating prvalues of them.<br></div></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/dc9396b6-00c6-4249-8988-a36f41c52519%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/dc9396b6-00c6-4249-8988-a36f41c52519=
%40isocpp.org</a>.<br />

------=_Part_1521_1776317284.1477837388206--

------=_Part_1520_927821942.1477837388206--

.
