220 30211 <621e1d86-492b-4ecc-96ba-4e0b74dfcb4e@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: enum_cast proposal
Date: Tue, 3 Jan 2017 19:58:52 -0800 (PST)
Lines: 97
Approved: news@gmane.org
Message-ID: <621e1d86-492b-4ecc-96ba-4e0b74dfcb4e@isocpp.org>
References: <efdf2357-00a6-408a-8772-12f99135a880@isocpp.org>
 <1d5db671-8ee9-49dc-937d-10a20f48fe73@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1189_1966822393.1483502332996"
X-Trace: blaine.gmane.org 1483502336 5024 195.159.176.226 (4 Jan 2017 03:58:56 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 4 Jan 2017 03:58:56 +0000 (UTC)
Cc: m.cencora@gmail.com, gmisocpp@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBB7PFWHBQKGQEA4YGI6Y@isocpp.org Wed Jan 04 04:58:52 2017
Return-path: <std-proposals+bncBCEKFTV6ZUMBB7PFWHBQKGQEA4YGI6Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f72.google.com ([74.125.83.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBB7PFWHBQKGQEA4YGI6Y@isocpp.org>)
	id 1cOciw-0000O0-4Y
	for gclcip-std-proposals@m.gmane.org; Wed, 04 Jan 2017 04:58:51 +0100
Original-Received: by mail-pg0-f72.google.com with SMTP id a190sf1281692283pgc.0
        for <gclcip-std-proposals@m.gmane.org>; Tue, 03 Jan 2017 19:58: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:cc: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=cQzWX3zbzGRfE+AQfXy9eSrIHv9xGUc23mY4JLUnGgQ=;
        b=0dOaWselCX0eFSOTKtkxiwx16cSVVG2ndFSCXWqzqtJDmkLzqFAla5MBixppNPDGhw
         7mRoMvG2edEAKtLtK7h4JP5OTptAJF7HX8a5rqMgA+KO8fe/lWFwxkYoARf9JDiOAIlN
         HrV9HGjZbfxGNoq3wiIzaHbpciuYCMrAUL+jeRJ3V614+kIlCLCOV+DL2RLNzJm+MiS/
         t5EnWU2U6sPr3hDo6x6l1DvnCpt3JliHA3gLzAyPN5VMdz9zlhOkwij+cGbRt+Ak9EHt
         n025vrwAIMa1Lge0NUMIz5yjkLJIn7g4s2dnpfoZ0hqmLItBi7S5yETaL1SXRnTKSjN2
         w/ow==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc: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=cQzWX3zbzGRfE+AQfXy9eSrIHv9xGUc23mY4JLUnGgQ=;
        b=Wv7Mm+xHL9xFTO7uYNFKZgcDaxcwuw2kK0ZsGCZ/pymhhp20F+c0ZYIXt/236omQ+8
         gPgIwTkcPkJQoaoF2s7nKm1+qladXsWlYIVDEAxQG0vxrKrTce8HUIaEcChQb9rY4PJq
         EXfepqMRvw3DyTXuKHzivfay1ocZ26v3P9/YEN0klWCkga7ihjHvfuG6s0NT+iT8inBc
         6YaW34Dq5xxfDKUstNVpUJEyAYBshErczwbbY/+ttRbwUdyCRRvqrMmvGtizSgB5rDay
         ACXiuWZxqYsqFkpXHxnJxFcKKMEEHeGPIWjK3MLs0lEcgyM2cyuLMYTxQVdpQZ8K3ajv
         fWLw==
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:cc: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=cQzWX3zbzGRfE+AQfXy9eSrIHv9xGUc23mY4JLUnGgQ=;
        b=pUH/8BXWsOz5PSY2GW8a03pqURbUEa0SVMSTMSgqPGtEdtB5bgvy1zNA45S4Oiz7GG
         1EwXs/eSPNiFVfnJ+YBLHtcE9XT1xgLHlgrTLZjt782cgdXAYIqx5B89UHz7k6vNXXPY
         YxhBuyptbc/7bVGr2fhbvvg3ads9C31Yzz5uSjA3nJaq70AmfhkP+9DCtalNejwww8ax
         +rd5FchQsOAm2hE8Fci3f8UmPHtOWMypx14IfEljnRAdllHj153po23pPb6zYsAR9xDJ
         HFDa8qXD64r/aSX31+XMmNQGmpeV+05z8k9jWsj5aMIsSqcjDl54I3+EeiTYXd3mjr81
         WAZA==
X-Gm-Message-State: AIkVDXI3Y3EoGuEyH8KlTYUiww9oC+2pjGQmOZb4EGXzXNElnYOV17aNde9VJhPGRigpRA==
X-Received: by 10.99.173.12 with SMTP id g12mr40475440pgf.39.1483502334081;
        Tue, 03 Jan 2017 19:58:54 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.33.198 with SMTP id s64ls31277124otb.22.gmail; Tue, 03 Jan
 2017 19:58:53 -0800 (PST)
X-Received: by 10.157.43.243 with SMTP id u106mr2294277ota.2.1483502333439;
        Tue, 03 Jan 2017 19:58:53 -0800 (PST)
In-Reply-To: <1d5db671-8ee9-49dc-937d-10a20f48fe73@isocpp.org>
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:30211
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30211>

------=_Part_1189_1966822393.1483502332996
Content-Type: multipart/alternative; 
	boundary="----=_Part_1190_1757428033.1483502332996"

------=_Part_1190_1757428033.1483502332996
Content-Type: text/plain; charset=UTF-8

On Tuesday, January 3, 2017 at 6:01:16 PM UTC-5, gmis...@gmail.com wrote:
>
>
> How about:
>
> enum class trafflic_light{ unknown, reg, yellow, green };
>
> traffic_light = traffic_light::unknown; // My default.
> bool success = make_enum(light, x); // Does not set light on failure. X of 
> any integral type
>

No, that requires the existence of `light`. C++ has too many APIs that 
needlessly require live objects already; we don't need another one.

On Tuesday, January 3, 2017 at 6:48:25 PM UTC-5, gmis...@gmail.com wrote:
>
>
> Just considering my earlier make_enum comment further, The ultimate 
> minimum for C++ is surely this?:
>
> traffic_light light{}; // whatever default.
> bool guaranteed_success = std::can_cast_enum<traffic_light>(x);
> if (guaranteed_success)
>  light = reinterpret_cast<traffic_light>(x);
> // else error condition.
>
> It separates the validity check from the conversion
>

That's actually a pretty good idea. Of course, there should be 
"higher-level" functionality like a direct `enum_cast` that throws and so 
forth, as discussed. But this way, people have the lowest-level tools to 
build their own functionality on top of the basic question.

-- 
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/621e1d86-492b-4ecc-96ba-4e0b74dfcb4e%40isocpp.org.

------=_Part_1190_1757428033.1483502332996
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, January 3, 2017 at 6:01:16 PM UTC-5, gmis...@g=
mail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr=
"><div><br></div><div>How about:</div><div><br></div><p>enum class trafflic=
_light{ unknown, reg, yellow, green };</p><div><br></div><div>traffic_light=
 =3D traffic_light::unknown; // My default.<br>bool success =3D make_enum(l=
ight, x); // Does not set light on failure. X of any integral type<br></div=
></div></blockquote><br>No,
 that requires the existence of `light`. C++ has too many APIs that=20
needlessly require live objects already; we don&#39;t need another one.<br>=
<br>On Tuesday, January 3, 2017 at 6:48:25 PM UTC-5, gmis...@gmail.com wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><br></=
div><div>Just considering my earlier make_enum comment further, The ultimat=
e minimum for C++ is surely this?:</div><div><br></div><div>traffic_light l=
ight{}; // whatever default.<br>bool guaranteed_success =3D std::can_cast_e=
num&lt;traffic_<wbr>light&gt;(x);</div><div>if (guaranteed_success)<br>=C2=
=A0light =3D reinterpret_cast&lt;traffic_<wbr>light&gt;(x);</div><div>// el=
se error condition.</div><div><br></div><div>It separates the validity chec=
k from the conversion</div></div></blockquote><div><br>That&#39;s actually =
a pretty good idea. Of course, there should be &quot;higher-level&quot; fun=
ctionality like a direct `enum_cast` that throws and so forth, as discussed=
.. But this way, people have the lowest-level tools to build their own funct=
ionality on top of the basic question.</div><br></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/621e1d86-492b-4ecc-96ba-4e0b74dfcb4e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/621e1d86-492b-4ecc-96ba-4e0b74dfcb4e=
%40isocpp.org</a>.<br />

------=_Part_1190_1757428033.1483502332996--

------=_Part_1189_1966822393.1483502332996--

.
