220 30180 <d4b84145-05e8-452f-ba08-dae9bbe34e04@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: m.cencora@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: enum_cast proposal
Date: Tue, 3 Jan 2017 08:22:52 -0800 (PST)
Lines: 188
Approved: news@gmane.org
Message-ID: <d4b84145-05e8-452f-ba08-dae9bbe34e04@isocpp.org>
References: <efdf2357-00a6-408a-8772-12f99135a880@isocpp.org> <1483532086.2yCkjVBYWJ@tjmaciei-mobl1> <bb835a83-0f69-4a76-97df-581c2a2ae8d8@isocpp.org>
 <2998762.etaySSRi7N@tjmaciei-mobl1>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1219_699239157.1483460572939"
X-Trace: blaine.gmane.org 1483460580 29072 195.159.176.226 (3 Jan 2017 16:23:00 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 3 Jan 2017 16:23:00 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD7YFUMJRYMBBXM7V7BQKGQESL6B6DA@isocpp.org Tue Jan 03 17:22:50 2017
Return-path: <std-proposals+bncBD7YFUMJRYMBBXM7V7BQKGQESL6B6DA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk0-f69.google.com ([209.85.213.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBD7YFUMJRYMBBXM7V7BQKGQESL6B6DA@isocpp.org>)
	id 1cORrO-0006Om-0T
	for gclcip-std-proposals@m.gmane.org; Tue, 03 Jan 2017 17:22:50 +0100
Original-Received: by mail-vk0-f69.google.com with SMTP id x186sf234596177vkd.1
        for <gclcip-std-proposals@m.gmane.org>; Tue, 03 Jan 2017 08:22:54 -0800 (PST)
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=CdxXX08pQPxDHEwCa/mPqUB1Q55Zy99xcQOtIL3DYt4=;
        b=vFP2jbrgGp4LPTIoErFPvY1il5p05/hoLhPrKKWG0469tvt/icOgUvAOOTW3fApUjv
         gR5izuGvOOdHGgxk1xWhK0kYP3gVlwmTKephHbbtFUfZdSdoVzLjMI/S9j6ukK52bKoM
         wyBT1Xxw+uzSUZZdVaH6Pp1JclCSsfVwPFmkoLIUg6QuGZfHvAcInEYi4okhusfb2Pf7
         xejk2jXgT0oTjkBfVvncCacd8g6AWF1eIgDvvIiVCPorAHyRDsE7ZZ5BFddtfS0dD6G6
         G11Sh8U90r5hkigywkiwWB2Ztu5j67diQXliCDraB8GVlOMuOaOZDeLIa8sSCMBjlpBv
         eo4g==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        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=CdxXX08pQPxDHEwCa/mPqUB1Q55Zy99xcQOtIL3DYt4=;
        b=r1wHqvziRixUYTQcuab3tIjvOTSSznFJO3zy30iuPGXMkyz4PLjJya+IRSvwM9S7r1
         QCVJ/f3MGXLImtjPbsyFmZZuITCyobrTTii2G3KeAufr+Jq5S0Qla+L/90GGEqxKvfpD
         UmInOHeExM+39G5ZKegXyZx4oMxqNIpSAhz1r9aDHe0ub1MOtpumDIJ+IArXefWeKkuz
         jIOPsFBaNS4JOq6YKlHKIJTDest6mey7XunxJYRkX0FRcXeak0+uOC05ENmio2UsGzUt
         9mG4JFb+Z238SiH8KcS6XpQKoPFUEz4MimJL0u/SmdPQptDQURJw3dRNsDPuO2l5Mu/n
         u8qg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        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=CdxXX08pQPxDHEwCa/mPqUB1Q55Zy99xcQOtIL3DYt4=;
        b=ePfXStubYwqETJMUbZGKFEUuephHaSy4LCCA5MM+RQMdJCXdchXplkoYEFJF54Sy78
         hMHw3c+cxndAdYcKsPMHzjmwASgg1GFKC3YORoMrwarREi0HuXSZ+oOlL6OI63fWImBy
         YKm/OEc2gNp0ZxRFXWUY1l6dSlv/JDr3tr9PqT2+bA+AbMpDlqYrmzVGD7k1my2x3bN1
         2a3lmTxH/KCvWQsRGXMjL0itvXfNhUkZlqs9m+LYF89aB1EXJFDJa1d54bUhVooeO4Yy
         TuBG623+cI74/z6oPTyKxATXBUQ0nZ48aSFml0jfKUdu+NC01W+VHaPDlL25rrNW1lEk
         o0tQ==
X-Gm-Message-State: AIkVDXK1zAxOsq0rh3ct0bNU2yJeOaSlBLwE3VBhWxM6ILFIOdXKxeiRVHTick9kPIpqYQ==
X-Received: by 10.176.75.3 with SMTP id h3mr28764015uaf.1.1483460574096;
        Tue, 03 Jan 2017 08:22:54 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.23.193 with SMTP id j59ls41817062otj.24.gmail; Tue, 03 Jan
 2017 08:22:53 -0800 (PST)
X-Received: by 10.157.17.3 with SMTP id g3mr2883516ote.8.1483460573373;
        Tue, 03 Jan 2017 08:22:53 -0800 (PST)
In-Reply-To: <2998762.etaySSRi7N@tjmaciei-mobl1>
X-Original-Sender: m.cencora@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:30180
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30180>

------=_Part_1219_699239157.1483460572939
Content-Type: multipart/alternative; 
	boundary="----=_Part_1220_5047470.1483460572939"

------=_Part_1220_5047470.1483460572939
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

W dniu wtorek, 3 stycznia 2017 16:56:35 UTC+1 u=C5=BCytkownik Thiago Maciei=
ra=20
napisa=C5=82:
>
> On ter=C3=A7a-feira, 3 de janeiro de 2017 07:06:10 BRST m.ce...@gmail.com=
=20
> <javascript:> wrote:=20
> > Compiler should synthesize a function like below:=20
> >=20
> > optional<color> enum_cast(int x)=20
> > {=20
> >     switch(x)=20
> >     {=20
> >         case red:=20
> >         case green:=20
> >         case blue:=20
> >             return static_cast<color>(x);=20
> >         default:=20
> >             return nullopt;=20
> >     }=20
> > }=20
>
> How do you know whether a use of enum_cast is compile-time or whether it=
=20
> is=20
> runtime?=20
>
>
I don't know and I don't care. The function should be constexpr to support=
=20
both cases.=20
=20

> static_cast is always compile time and always succeeds or produces a=20
> compilation error. Therefore, checking at runtime is unnecessary.=20
>
> dynamic_cast is almost always runtime and its result needs to be checked=
=20
> at=20
> runtime.=20
>
> Also, where did that optional come from? If it's going to use optional,=
=20
> then=20
> it needs to be a library feature.=20
>

Just a first idea on dealing with failure cases. Not really important at=20
this point.

What I'd like to hear now is whether anyone else would find such a=20
functionality useful?
Do you consider it a good idea to put it into C++ standard/library?
=20

>
> > Of course it could implement it more efficently (as range check instead=
=20
> of=20
> > switch if all enumerators are consecutive integers).=20
>
> One would expect the compilers to be smart enough to do that with a switc=
h=20
> block that is contiguous. Still, QoI issue.=20
>
> --=20
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org=20
>    Software Architect - Intel Open Source Technology Center=20
>
>

--=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/d4b84145-05e8-452f-ba08-dae9bbe34e04%40isocpp.or=
g.

------=_Part_1220_5047470.1483460572939
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">W dniu wtorek, 3 stycznia 2017 16:56:35 UTC+1 u=C5=BCytkow=
nik Thiago Macieira napisa=C5=82:<blockquote class=3D"gmail_quote" style=3D=
"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex=
;">On ter=C3=A7a-feira, 3 de janeiro de 2017 07:06:10 BRST <a href=3D"javas=
cript:" target=3D"_blank" gdf-obfuscated-mailto=3D"3-AvBdp2CwAJ" rel=3D"nof=
ollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" oncli=
ck=3D"this.href=3D&#39;javascript:&#39;;return true;">m.ce...@gmail.com</a>=
 wrote:
<br>&gt; Compiler should synthesize a function like below:
<br>&gt;=20
<br>&gt; optional&lt;color&gt; enum_cast(int x)
<br>&gt; {
<br>&gt; =C2=A0 =C2=A0 switch(x)
<br>&gt; =C2=A0 =C2=A0 {
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 case red:
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 case green:
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 case blue:
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return static_cast&lt;co=
lor&gt;(x);
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 default:
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return nullopt;
<br>&gt; =C2=A0 =C2=A0 }
<br>&gt; }
<br>
<br>How do you know whether a use of enum_cast is compile-time or whether i=
t is=20
<br>runtime?
<br>
<br></blockquote><div><br></div><div>I don&#39;t know and I don&#39;t care.=
 The function should be constexpr to support both cases.=C2=A0</div><div>=
=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">static_cast is alw=
ays compile time and always succeeds or produces a=20
<br>compilation error. Therefore, checking at runtime is unnecessary.
<br>
<br>dynamic_cast is almost always runtime and its result needs to be checke=
d at=20
<br>runtime.
<br>
<br>Also, where did that optional come from? If it&#39;s going to use optio=
nal, then=20
<br>it needs to be a library feature.
<br></blockquote><div><br></div><div>Just a first idea on dealing with fail=
ure cases. Not really important at this point.</div><div><br></div><div>Wha=
t I&#39;d like to hear now is whether anyone else would find such a functio=
nality useful?</div><div>Do you consider it a good idea to put it into C++ =
standard/library?</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" s=
tyle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-le=
ft: 1ex;">
<br>&gt; Of course it could implement it more efficently (as range check in=
stead of
<br>&gt; switch if all enumerators are consecutive integers).
<br>
<br>One would expect the compilers to be smart enough to do that with a swi=
tch=20
<br>block that is contiguous. Still, QoI issue.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.hr=
ef=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return t=
rue;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.=
com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH=
GRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;=
http://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1=
\x26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;">kde.org</a=
>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote></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/d4b84145-05e8-452f-ba08-dae9bbe34e04%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d4b84145-05e8-452f-ba08-dae9bbe34e04=
%40isocpp.org</a>.<br />

------=_Part_1220_5047470.1483460572939--

------=_Part_1219_699239157.1483460572939--

.
