220 30178 <ea4c8ec9-5f0e-42fb-8928-35bc47e4fd96@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:12:29 -0800 (PST)
Lines: 104
Approved: news@gmane.org
Message-ID: <ea4c8ec9-5f0e-42fb-8928-35bc47e4fd96@isocpp.org>
References: <efdf2357-00a6-408a-8772-12f99135a880@isocpp.org>
 <1daf67ad-8ee7-4ad6-937b-027ba6020c14@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1183_727352945.1483459949335"
X-Trace: blaine.gmane.org 1483459960 25477 195.159.176.226 (3 Jan 2017 16:12:40 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 3 Jan 2017 16:12:40 +0000 (UTC)
Cc: m.cencora@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD7YFUMJRYMBB4M2V7BQKGQEJTAUIUI@isocpp.org Tue Jan 03 17:12:36 2017
Return-path: <std-proposals+bncBD7YFUMJRYMBB4M2V7BQKGQEJTAUIUI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f199.google.com ([209.85.161.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBD7YFUMJRYMBB4M2V7BQKGQEJTAUIUI@isocpp.org>)
	id 1cORhN-0005Gy-VI
	for gclcip-std-proposals@m.gmane.org; Tue, 03 Jan 2017 17:12:30 +0100
Original-Received: by mail-yw0-f199.google.com with SMTP id b66sf528262041ywh.2
        for <gclcip-std-proposals@m.gmane.org>; Tue, 03 Jan 2017 08:12:34 -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=YrGua2Sj5NBcHgrDqA8dI3m5o+7jCTOVLKxuxy7Ciaw=;
        b=EyFSfTmV1AW+XtwaW0G+sJYjQ+R5zpaPFSlG6nGiGQPd2f05NmFU4YaK9JpegbHBBK
         tgPpuhm54aITOFAC3WxH4MbHh3ts4nvPAbAtRr4diaTY/jbU4OsmCaivFoqwEK+VxxfP
         yMzSdpinBw+COlN9gcaacFaO6cRbpx9Ox2+261Ocw5rAytmq3frpKp+CE2bB5kp99rZ5
         ND5Dqv/jvvX5DldlVjMByejE/tfdzLsGbS8ka4dqo6hBTEE7i7gxS48O3iDiAez7PFG7
         K4KVYEtpCDSNg9A30EEGC+h7NdNYS9nbM5l2c/gpQZCWDV+5rNyGmdkt+3MP8NVOsLe4
         eqpA==
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=YrGua2Sj5NBcHgrDqA8dI3m5o+7jCTOVLKxuxy7Ciaw=;
        b=lKwX1umrHL8h80GYJ0hKLosT9Pn81h9ruHMC2OlHLYujO82B1fJUeOORsycBqWRqrO
         ksbo6YL7XHc3mMSt5Ids85M+xxTsPqXnubIhgQTLPwMrvvEKRcDx/llBF3lDox/LzlfB
         y1CVkK7PycRG3Va+Ni9rMne6j1lvfCDXc5UhlNQAFNMDySHb87es8jkYWffZE7m4Jke9
         UcPFfl84jAHKiskp8UnUulwt0XV/yuIWlZHr97XkxDBb1cr9ZVfYW2wUrUn+j/W/bDXi
         tIRW0psE3wD36+Os6g2FbHXeEhXf6vw9SJkm6Hvz2s5aZV+eurGJr7rvECGWjgFddJu8
         SLew==
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=YrGua2Sj5NBcHgrDqA8dI3m5o+7jCTOVLKxuxy7Ciaw=;
        b=f1tA5xmWsBZkZW31REo5npiHrKPESKgcdoPFjbQcvHYL9YsE+21kzEb9WpYD6ZbP7J
         XlvDmPjYiTuPpoga5MM+HS1PBr7zV7bWqk+3lLBUctwGArpBNu6pTRp0vLcmj1kdGHM+
         toihtDi7++Y3h9uj4kqlZ4JpqfR8moe/GsO5YQgqtQtrcVa3JHolncWyLGWGrOEp3JEN
         i3rT+MhJ82P7O7kkctZOWwktiJLXFD5xEZGYD/9HoT+jK+yVnnUINWempiDLHZi66isl
         Vdtwf7Zfq+pZvynJ2FDkER6AiQOtvofg/kvhio51MJad9zq5ClNMH90glznWSBHVBU78
         rnMA==
X-Gm-Message-State: AIkVDXIdGupK8TOEey3ho1/IuwEnZHy2dpwt3r2jWyagG4c/YhWx/idfFedejkgc/WXgbQ==
X-Received: by 10.13.240.135 with SMTP id z129mr18295586ywe.121.1483459953905;
        Tue, 03 Jan 2017 08:12:33 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.31.122 with SMTP id x55ls21834060otx.36.gmail; Tue, 03 Jan
 2017 08:12:33 -0800 (PST)
X-Received: by 10.157.18.211 with SMTP id g77mr2879291otg.14.1483459953226;
        Tue, 03 Jan 2017 08:12:33 -0800 (PST)
In-Reply-To: <1daf67ad-8ee7-4ad6-937b-027ba6020c14@isocpp.org>
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:30178
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30178>

------=_Part_1183_727352945.1483459949335
Content-Type: multipart/alternative; 
	boundary="----=_Part_1184_630430329.1483459949335"

------=_Part_1184_630430329.1483459949335
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

W dniu wtorek, 3 stycznia 2017 16:21:37 UTC+1 u=C5=BCytkownik Nicol Bolas=
=20
napisa=C5=82:
>
> On Tuesday, January 3, 2017 at 4:56:05 AM UTC-5, m.ce...@gmail.com wrote:
>>
>> Hi,
>>
>> I propose to add a enum_cast function that safely casts int value to a=
=20
>> target enum type if int value represents a valid enumerator.
>>
>
> It should not return an `optional`. It should either correctly cast or=20
> *throw*. Why?
>
> Consider how users will use it. You're going to see a lot of people doing=
=20
> `enum_cast<>().value()`. Which will incur needless copying if the=20
> conversion worked. And if it doesn't work, an exception will be thrown.
>
> What exception will that be? `bad_optional_access`. Which is about as=20
> useless as exceptions get as far as tracking down the problem. A far more=
=20
> descriptive exception would be `bad_enum_cast`.
>
> I would say that you should provide both APIs: `enum_cast` for conversion=
=20
> or throwing. And `optional_enum_cast` or somesuch for conversion into an=
=20
> `optional<enum>`.
>

At this point I consider chosing a error reporting way bike-shedding.

Let's focus on actual functionality it provides for now:
check if provided int corresponds to any of the enumerators of given enum.

--=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/ea4c8ec9-5f0e-42fb-8928-35bc47e4fd96%40isocpp.or=
g.

------=_Part_1184_630430329.1483459949335
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">W dniu wtorek, 3 stycznia 2017 16:21:37 UTC+1 u=C5=BCytkow=
nik Nicol Bolas napisa=C5=82:<blockquote class=3D"gmail_quote" style=3D"mar=
gin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><=
div dir=3D"ltr">On Tuesday, January 3, 2017 at 4:56:05 AM UTC-5, <a>m.ce...=
@gmail.com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;ma=
rgin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"lt=
r">Hi,<div><br></div><div>I propose to add a enum_cast function that safely=
 casts int value to a target enum type if int value represents a valid enum=
erator.</div></div></blockquote><div><br>It should not return an `optional`=
.. It should either correctly cast or <i>throw</i>. Why?<br><br>Consider how=
 users will use it. You&#39;re going to see a lot of people doing `enum_cas=
t&lt;&gt;().value()`. Which will incur needless copying if the conversion w=
orked. And if it doesn&#39;t work, an exception will be thrown.<br><br>What=
 exception will that be? `bad_optional_access`. Which is about as useless a=
s exceptions get as far as tracking down the problem. A far more descriptiv=
e exception would be `bad_enum_cast`.<br><br>I would say that you should pr=
ovide both APIs: `enum_cast` for conversion or throwing. And `optional_enum=
_cast` or somesuch for conversion into an `optional&lt;enum&gt;`.</div></di=
v></blockquote><div><br></div><div>At this point I consider chosing a error=
 reporting way bike-shedding.</div><div><br></div><div>Let&#39;s focus on a=
ctual functionality it provides for now:</div><div>check if provided int co=
rresponds to any of the enumerators of given enum.</div><div><br></div></di=
v>

<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/ea4c8ec9-5f0e-42fb-8928-35bc47e4fd96%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ea4c8ec9-5f0e-42fb-8928-35bc47e4fd96=
%40isocpp.org</a>.<br />

------=_Part_1184_630430329.1483459949335--

------=_Part_1183_727352945.1483459949335--

.
