220 8395 <52C7F46C.3060702@wanadoo.fr> article
Path: news.gmane.org!not-for-mail
From: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: [exception_ptr] exception_ptr_cast: cast to the
 stored exception a la any_cast
Date: Sat, 04 Jan 2014 12:45:48 +0100
Lines: 178
Approved: news@gmane.org
Message-ID: <52C7F46C.3060702@wanadoo.fr>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------090606000102070200000607"
X-Trace: ger.gmane.org 1388835945 31948 80.91.229.3 (4 Jan 2014 11:45:45 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 4 Jan 2014 11:45:45 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDH67CONY4PBB27IT6LAKGQE6TFVVII@isocpp.org Sat Jan 04 12:45:51 2014
Return-path: <std-proposals+bncBDH67CONY4PBB27IT6LAKGQE6TFVVII@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-la0-f70.google.com ([209.85.215.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDH67CONY4PBB27IT6LAKGQE6TFVVII@isocpp.org>)
	id 1VzPfn-00017N-SY
	for gclcip-std-proposals@m.gmane.org; Sat, 04 Jan 2014 12:45:47 +0100
Original-Received: by mail-la0-f70.google.com with SMTP id e16sf1881274lan.5
        for <gclcip-std-proposals@m.gmane.org>; Sat, 04 Jan 2014 03:45:47 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to
         :subject:x-original-sender:x-original-authentication-results
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe:content-type;
        bh=k6MDUIF+anVhABiPTBdJ+JmmnELyZUbA/kwM0gMK6TQ=;
        b=T8T8LAKWmnnQgRu8IYJZJjuZthFEk7bsUhC3JlzVBEMf0fXzNhtAaob6Dc3GFw3nEz
         DKAf8AB6eJtEDit0P+VpoXGMwsrqqlcfJcoA/ZEzMg343vzCVS8/7hLX+BwxwN3AftHU
         K4/egseWo53k4cSeLsMa6vn0UcL6eIrC8z9sU/eJsEKFO+Ksuy9XIUBKwyd09vpGUfvB
         pfXKc8ogtDLEiYDoR9uv4jjEJt3Otwaonx5+ppO5mjuFEFZBieVv2Gxwa2VWJ2dZSbdS
         5wZX04MamJAsTZFkQ/yiuXc4x3WBIsrsjgWlPTv7GXYbbpx4pxAPIsVY6wJvzMXV11/M
         G1Bg==
X-Gm-Message-State: ALoCoQkVoKWaYULOGcsQDDAb6qqrjs24iHwaHWu7qrpUN/+kBnp9Kkc30K+sH6fvbomBIkd/6hZH
X-Received: by 10.112.130.196 with SMTP id og4mr25784956lbb.13.1388835947456;
        Sat, 04 Jan 2014 03:45:47 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.94.34 with SMTP id cz2ls200952wib.41.gmail; Sat, 04 Jan
 2014 03:45:46 -0800 (PST)
X-Received: by 10.194.2.70 with SMTP id 6mr47018085wjs.25.1388835946627;
        Sat, 04 Jan 2014 03:45:46 -0800 (PST)
Original-Received: from smtp.smtpout.orange.fr (smtp03.smtpout.orange.fr. [80.12.242.125])
        by mx.google.com with ESMTP id m13si4889419wjr.119.2014.01.04.03.45.46
        for <std-proposals@isocpp.org>;
        Sat, 04 Jan 2014 03:45:46 -0800 (PST)
Received-SPF: neutral (google.com: 80.12.242.125 is neither permitted nor denied by best guess record for domain of vicente.botet@wanadoo.fr) client-ip=80.12.242.125;
Original-Received: from new-host.home ([92.139.143.25])
	by mwinf5d50 with ME
	id 9nll1n00D0Z5MbQ03nllbh; Sat, 04 Jan 2014 12:45:46 +0100
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
X-Original-Sender: vicente.botet@wanadoo.fr
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 80.12.242.125 is neither permitted nor denied by best guess
 record for domain of vicente.botet@wanadoo.fr) smtp.mail=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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:8395
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8395>

This is a multi-part message in MIME format.
--------------090606000102070200000607
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi,

I'm working on a proposal of an expected<T> class based on the 
Expected<T> from Alexandrescu.
Expected<T> provides a function hasException defined as follows:

template <class E>
bool hasException() const {
   try {
      if (!gotHam) std::rethrow_exception(spam);
   } catch (const E& object) {
      return true;
   } catch (...) {
   }
   return false;
}

But this function doesn't allow to get the stored exception so that we 
cannot access specifics members in exception E.

if (y.hasException<NotDivisible>())
{
.... // no way to get the values that are not dividible
}

Of course, the user could always do

   try {
      if (! y.valid()) std::rethrow_exception(y.exception_ptr());
   } catch (const NotDivisible& ex) {
std::cout <<ex.num <<"," <<ex.den<<std::endl;
   } catch (...) {
   }

But, this is not optimal, as we need to use a try-catch block and 
rethrow the exception.

I would like to define a dynamic cast that returns a pointer to the 
stored exception it the type match

template <class E, class T>
const E* expected_cast(const expected<T>*);

if (auto ex = expected_cast<NotDivisible*>(&y))
{
std::cout <<ex->num <<"," <<ex->den<<std::endl;
}

But I don't see how to implement it without having the possibility to 
cast the exception_ptr instance to the stored exception. Do you know how 
this can be implemented with the current exception_ptr interface?

If instead of storing the exception on a exception_ptr, we store it on 
the std::experimental::any we can use std::experimental::any_cast to get 
the stored exception. However, while std::experimental::any could be 
used to store any explicit exception, it cannot be used to store the 
current exception.

Is there a way to define a exception_ptr_cast (similar to the one of 
std::experimental::any_cast) for std::exception_ptr?
Are there some restrictions to the stored exceptions?
It is worth writing a standard proposal?

Best,
Vicente


-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--------------090606000102070200000607
Content-Type: text/html; charset=ISO-8859-1

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi,<br>
    <br>
    I'm working on a proposal of an expected&lt;T&gt; class based on the
    Expected&lt;T&gt; from Alexandrescu.<br>
    Expected&lt;T&gt; provides a function hasException defined as
    follows:<br>
    <br>
    <meta http-equiv="Content-Type" content="text/html;
      charset=ISO-8859-1">
    <title></title>
    template &lt;class E&gt;<br>
    bool hasException() const {<br>
    &nbsp; try {<br>
    &nbsp; &nbsp;&nbsp; if (!gotHam) std::rethrow_exception(spam);<br>
    &nbsp; } catch (const E&amp; object) {<br>
    &nbsp; &nbsp;&nbsp; return true;<br>
    &nbsp; } catch (...) {<br>
    &nbsp; }<br>
    &nbsp; return false;<br>
    }<br>
    <br>
    But this function doesn't allow to get the stored exception so that
    we cannot access specifics members in exception E.<br>
    <br>
    if (y.hasException&lt;NotDivisible&gt;()) <br>
    {<br>
    ... // no way to get the values that are not dividible<br>
    }<br>
    <br>
    Of course, the user could always do<br>
    <br>
    &nbsp; try {<br>
    &nbsp; &nbsp;&nbsp; if (! y.valid()) std::rethrow_exception(y.exception_ptr());<br>
    &nbsp; } catch (const NotDivisible&amp; ex) {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;
    std::cout &lt;&lt;ex.num &lt;&lt;","
    &lt;&lt;ex.den&lt;&lt;std::endl;<br>
    &nbsp; } catch (...) {<br>
    &nbsp; }<br>
    <br>
    But, this is not optimal, as we need to use a try-catch block and
    rethrow the exception.<br>
    <br>
    I would like to define a dynamic cast that returns a pointer to the
    stored exception it the type match<br>
    <br>
    template &lt;class E, class T&gt;<br>
    const E* expected_cast(const expected&lt;T&gt;*);<br>
    <br>
    if (auto ex = expected_cast&lt;NotDivisible*&gt;(&amp;y)) <br>
    {<br>
    &nbsp;&nbsp;
    std::cout &lt;&lt;ex-&gt;num &lt;&lt;"," &lt;&lt;ex-&gt;den&lt;&lt;std::endl;<br>
    }<br>
    <br>
    But I don't see how to implement it without having the possibility
    to cast the exception_ptr instance to the stored exception. Do you
    know how this can be implemented with the current exception_ptr
    interface?<br>
    <br>
    If instead of storing the exception on a exception_ptr, we store it
    on the std::experimental::any we can use std::experimental::any_cast
    to get the stored exception. However, while std::experimental::any
    could be used to store any explicit exception, it cannot be used to
    store the current exception.<br>
    <br>
    Is there a way to define a exception_ptr_cast (similar to the one of
    std::experimental::any_cast) for std::exception_ptr?<br>
    Are there some restrictions to the stored exceptions?<br>
    It is worth writing a standard proposal?<br>
    <br>
    Best,<br>
    Vicente<br>
    <br>
    <br>
  </body>
</html>

<p></p>

-- <br />
&nbsp;<br />
--- <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 email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

--------------090606000102070200000607--

.
