220 30463 <587512E1.1050708@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: enum_cast proposal
Date: Tue, 10 Jan 2017 11:59:13 -0500
Lines: 37
Approved: news@gmane.org
Message-ID: <587512E1.1050708@gmail.com>
References: <efdf2357-00a6-408a-8772-12f99135a880@isocpp.org>
 <57258435-5d82-48e7-8ed7-3c38682418fb@isocpp.org>
 <a35d9f20-9e4f-4789-b7e5-5cb08f99e6bd@isocpp.org>
 <58750288.5080004@gmail.com>
 <e85f0d46-f244-42fe-a276-b4e18b3d627f@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: blaine.gmane.org 1484067559 1079 195.159.176.226 (10 Jan 2017 16:59:19 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 10 Jan 2017 16:59:19 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.1.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBY5F2TBQKGQELLUN6NI@isocpp.org Tue Jan 10 17:59:14 2017
Return-path: <std-proposals+bncBC37LBFWUIFBBY5F2TBQKGQELLUN6NI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pf0-f199.google.com ([209.85.192.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBY5F2TBQKGQELLUN6NI@isocpp.org>)
	id 1cQzlP-0007zn-W2
	for gclcip-std-proposals@m.gmane.org; Tue, 10 Jan 2017 17:59:12 +0100
Original-Received: by mail-pf0-f199.google.com with SMTP id z128sf292424036pfb.4
        for <gclcip-std-proposals@m.gmane.org>; Tue, 10 Jan 2017 08:59:16 -0800 (PST)
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=ziQDTDDLjjsfR17N75ISVMUKHNYoh/uAmU/JIqOMIRk=;
        b=zmahQr4KMwqhVgi6D7nUsEP2YsgwFVtxM6GAe9n8DSB6AoRPwbbn0txhe2CSCTbPNp
         LlukwliivEoC5SC/szMNoZvcCs9etO+j/kxipuBaHApCIthZsR/Nvk7ofDpwwaFn7Yt7
         dTWwivJcMRXwruEhyAvTmkPjT3DfaBKQfOKfB3ruIUMJjb66orl+bPnEV9nXFV26cTDT
         9XjZCI1hbrE2WslEsRMF4/lMz0L+qPobbsLgW/KRnkdcnahmtz8TfogfuzN+hoIKDQdK
         EBc5tdHyjEvk5o99zLPUWPVxk4LLCVnZp3VTVc6ANt43FRiY7ZEFnf+GSI9shmhcwZQZ
         z41w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        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=ziQDTDDLjjsfR17N75ISVMUKHNYoh/uAmU/JIqOMIRk=;
        b=nLvfe9/VIeEa5mhnifTwE1226nMlg7yLVa0qIv23ErXEOx91zKMD0p9z7mQR2aCCuq
         W9Nj7MQW1MIEXvmO+JwsmgyKPCUW6sAZJHpcFqsd70R7vK2N8gK06Yn0BFYCYhNdEtTp
         5UXxnFr+3Zd3T/J7f+uZewzd/v+ZUfXkXr1nsmcIwYFdhh62BDvGG0vEjKHNQdh661yM
         h4A1WvU3U60kw+qWbSn3HSziHhM2SbJzvhQbMJQoqQvBVqr9XLv2x5uZdm4hOu4UjRUb
         a8QQXCiEaVgbVr09HE8DukZwdBd6oLnHcILy2+poAcvogjPRwJbsNxW5CU1pHOPdQMDB
         JoXg==
X-Gm-Message-State: AIkVDXIXPwoV+kOizApPD5RRa9pCa1MTC3eB4Kcsol0BGNSWvXKTMy8pc16vMWECCGa5Qg==
X-Received: by 10.98.218.85 with SMTP id w21mr177620pfl.41.1484067555863;
        Tue, 10 Jan 2017 08:59:15 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.17.154 with SMTP id v26ls1993923otf.0.gmail; Tue, 10 Jan
 2017 08:59:15 -0800 (PST)
X-Received: by 10.37.125.131 with SMTP id y125mr896132ybc.192.1484067555279;
        Tue, 10 Jan 2017 08:59:15 -0800 (PST)
Original-Received: from mail-yw0-x22b.google.com (mail-yw0-x22b.google.com. [2607:f8b0:4002:c05::22b])
        by mx.google.com with ESMTPS id n4si769149ywe.234.2017.01.10.08.59.15
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 10 Jan 2017 08:59:15 -0800 (PST)
Received-SPF: pass (google.com: domain of mwoehlke.floss@gmail.com designates 2607:f8b0:4002:c05::22b as permitted sender) client-ip=2607:f8b0:4002:c05::22b;
Original-Received: by mail-yw0-x22b.google.com with SMTP id l19so7954795ywc.2
        for <std-proposals@isocpp.org>; Tue, 10 Jan 2017 08:59:15 -0800 (PST)
X-Received: by 10.13.206.132 with SMTP id q126mr3670927ywd.311.1484067554813;
        Tue, 10 Jan 2017 08:59:14 -0800 (PST)
Original-Received: from [192.168.1.173] (tripoint.kitware.com. [66.194.253.20])
        by smtp.googlemail.com with ESMTPSA id x185sm1140329ywe.35.2017.01.10.08.59.13
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 10 Jan 2017 08:59:14 -0800 (PST)
In-Reply-To: <e85f0d46-f244-42fe-a276-b4e18b3d627f@isocpp.org>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of
 mwoehlke.floss@gmail.com designates 2607:f8b0:4002:c05::22b as permitted
 sender) smtp.mailfrom=mwoehlke.floss@gmail.com;       dmarc=pass (p=NONE
 sp=NONE dis=NONE) header.from=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:30463
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30463>

On 2017-01-10 11:20, Nicol Bolas wrote:
> On Tuesday, January 10, 2017 at 10:49:34 AM UTC-5, Matthew Woehlke wrote:
>> On 2017-01-10 10:31, m.ce...@gmail.com <javascript:> wrote: 
>>> For sure baseline API must be exception-free. 
>>> Do we really want to additionally support API that throws on error? 
>>
>> I *really* hope we can use something like std::expected; this is a 
>> textbook use case for that, and makes it trivial to have a 
>> throw-on-error API (just grab the value from the expected without 
>> checking it first; this will turn around and throw if the value is not 
>> there).
> 
> But the fact that it's throwing the wrong exception makes it useless from 
> an exception handling perspective.

Huh? I'm talking about std::expected, not std::optional. If you didn't
get a value, you get whatever error/exception (preferably an exception
in this case, since it doesn't need more storage than the enum and thus
doesn't cost extra) the API stuffed in instead, which would presumably
be a std::range_error or std::bad_enum_cast or whatever. IOW, the *SAME*
exception that an API that throws right away would throw.

> * `enum_cast`: Converts to the enumeration type, or throws if it cannot.
> * `enum_cast_opt`: Returns an `optional<Enum>`.

These can be combined with no loss of function into one API that returns
a std::expected or similar.

-- 
Matthew

-- 
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/587512E1.1050708%40gmail.com.

.
