220 29256 <74d02121-9633-b6d1-1187-2a9ab660089d@wanadoo.fr> article
Path: news.gmane.org!.POSTED!not-for-mail
From: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: explicit conversion from enum class to its
 underlying type
Date: Sun, 30 Oct 2016 14:53:37 +0100
Lines: 161
Approved: news@gmane.org
Message-ID: <74d02121-9633-b6d1-1187-2a9ab660089d@wanadoo.fr>
References: <4afed494-4fc5-4b06-b3e7-255aa293068e@isocpp.org>
 <f380095f-96be-d02f-584b-6821f70a20b2@wanadoo.fr>
 <1c81b80e-33b8-4de3-9bf7-94656e8b98f5@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------5BF172B001C10234D4F00A99"
X-Trace: blaine.gmane.org 1477835634 19055 195.159.176.226 (30 Oct 2016 13:53:54 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 30 Oct 2016 13:53:54 +0000 (UTC)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0)
 Gecko/20100101 Thunderbird/45.4.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDH67CONY4PBBZHW27AAKGQE3XJRX6A@isocpp.org Sun Oct 30 14:53:49 2016
Return-path: <std-proposals+bncBDH67CONY4PBBZHW27AAKGQE3XJRX6A@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wm0-f72.google.com ([74.125.82.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDH67CONY4PBBZHW27AAKGQE3XJRX6A@isocpp.org>)
	id 1c0qYM-0003Aa-Jx
	for gclcip-std-proposals@m.gmane.org; Sun, 30 Oct 2016 14:53:39 +0100
Original-Received: by mail-wm0-f72.google.com with SMTP id r68sf5861171wmd.0
        for <gclcip-std-proposals@m.gmane.org>; Sun, 30 Oct 2016 06:53:41 -0700 (PDT)
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=2+/k+saPdLJGfDxAHLEG9ovPWm4lSGLDAsiKUVs2G2M=;
        b=KFIlVN5q8gThN2pnafsJtSh7JuqXxj09sFGATaq1DhzjOzQvDnRTzH6AIZ7UC58wVs
         vwCj1IxjL8KlKagP4vKDNXs7HowMn18OZHETHAkYdpZWG7QescSrp/WrMTDOs/Mrb4P6
         2GC7um1o2AzqameYrgphUL+RPpBrlu7oS/L6u+1cLLu6G5IYymP6MpUKzCRemiIo8rdC
         9fI3sOZ+JdgC5ze3Saq1O/pnmxyLJay/omJnUbvheQ+cmNyTOJQyRSVNo7Ppaud1gBM1
         W8PZS7jRoQOi0N4YcomtJ+AqAS8CJoE8s93mERPNvGcbb5aKCij1UGctyNN+ljFyyyPk
         5E5Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        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=2+/k+saPdLJGfDxAHLEG9ovPWm4lSGLDAsiKUVs2G2M=;
        b=OzgLW2TwnfDK44V4jKztlpRVgaa2TFZgY1EnQ8DoCR7KuoWASVrqlaetqK9MLbPV6d
         7zFY1tE4YBmNywa6AczRGu/AJC9AL7J6FbHESdtEt8lAlz3gWEtDaNp9V6xWD3SoVG9M
         D8iyLZ5gEKj5MJrPjs98BpPrb43XVhev4u1SS1bWYdicwrn8fN6ezgr3QDfYKTZQmqti
         oZxK/ZkVmMMdVTi5hVVCXaV7WeFPl4mrmVptvFmw9IFd54qTEaOc10yDp1MaUijjK6cy
         wsZoqRQXmSXhghjVJHF9hJm1m692uD5luuQAiIIWLoEabQwY0eJPiWdlLYEJ9WMUmXAz
         Lq/Q==
X-Gm-Message-State: ABUngvcT6rPryW2YMJa9m3Nls5AUQVL9XB9hXN05JrDQC+JXcXQHCkam37tI7o3VTgCxUw==
X-Received: by 10.28.198.10 with SMTP id w10mr495464wmf.7.1477835621051;
        Sun, 30 Oct 2016 06:53:41 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.198.10 with SMTP id w10ls1156185wmf.7.canary-gmail; Sun, 30
 Oct 2016 06:53:39 -0700 (PDT)
X-Received: by 10.28.74.67 with SMTP id x64mr7255558wma.82.1477835619901;
        Sun, 30 Oct 2016 06:53:39 -0700 (PDT)
Original-Received: from smtp.smtpout.orange.fr (smtp07.smtpout.orange.fr. [80.12.242.129])
        by mx.google.com with ESMTPS id s5si24978403wjk.122.2016.10.30.06.53.39
        for <std-proposals@isocpp.org>
        (version=TLS1 cipher=AES128-SHA bits=128/128);
        Sun, 30 Oct 2016 06:53:39 -0700 (PDT)
Received-SPF: neutral (google.com: 80.12.242.129 is neither permitted nor denied by best guess record for domain of vicente.botet@wanadoo.fr) client-ip=80.12.242.129;
Original-Received: from pc29.home ([2.13.11.7])
	by mwinf5d30 with ME
	id 1ptd1u0060973YJ03ptd4G; Sun, 30 Oct 2016 14:53:39 +0100
X-ME-Helo: pc29.home
X-ME-Auth: dmljZW50ZS5ib3RldEB3YW5hZG9vLmZy
X-ME-Date: Sun, 30 Oct 2016 14:53:39 +0100
X-ME-IP: 2.13.11.7
In-Reply-To: <1c81b80e-33b8-4de3-9bf7-94656e8b98f5@isocpp.org>
X-Original-Sender: vicente.botet@wanadoo.fr
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 80.12.242.129 is neither permitted nor denied by best guess
 record for domain of vicente.botet@wanadoo.fr) smtp.mailfrom=vicente.botet@wanadoo.fr
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:29256
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29256>

This is a multi-part message in MIME format.
--------------5BF172B001C10234D4F00A99
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

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=20
> 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 the underlying type?
>>
>>     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.
>
>     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

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

--=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/74d02121-9633-b6d1-1187-2a9ab660089d%40wanadoo.f=
r.

--------------5BF172B001C10234D4F00A99
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">Le 30/10/2016 =C3=A0 13:20, Nicol Bolas =
a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote
      cite=3D"mid:1c81b80e-33b8-4de3-9bf7-94656e8b98f5@isocpp.org"
      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.8ex;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't it?<br=
>
            <br>
            =C2=A0=C2=A0=C2=A0 bool(e)<br>
          </div>
        </blockquote>
        <div><br>
          No, it doesn'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>
    <br>
    <a class=3D"moz-txt-link-freetext" href=3D"http://melpon.org/wandbox/pe=
rmlink/TnVrIdj3wz76l7b4">http://melpon.org/wandbox/permlink/TnVrIdj3wz76l7b=
4</a><br>
    <br>
    enum class SkipUnused : bool { No, Yes };<br>
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SkipUnused e{};<br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bool b1 {bool(e)}; (void)b1;=
<br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bool b2 =3Dbool(e); (void)b2=
;<br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 b1 =3D bool(e);<br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (bool(e)) <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std:=
:cout &lt;&lt; "Yes\n";<br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std:=
:cout &lt;&lt; "No\n";<br>
    <br>
    Maybe there is a bug in both compilers ;-)<br>
    <br>
    Vicente<br>
  </body>
</html>

<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/74d02121-9633-b6d1-1187-2a9ab660089d%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/74d02121-9633-b6d1-1187-2a9ab660089d=
%40wanadoo.fr</a>.<br />

--------------5BF172B001C10234D4F00A99--

.
