Topic: [exception_ptr] exception_ptr_cast: cast to


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Mon, 06 Jan 2014 19:16:25 +0100
Raw View
This is a multi-part message in MIME format.
--------------050805000700070007040300
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 06/01/14 16:33, Cassio Neri a =E9crit :
>
>
> On Saturday, January 4, 2014 11:45:48 AM UTC, Vicente J. Botet Escriba=20
> wrote:
>
>
>     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 =3D expected_cast<NotDivisible*>(&y))
>     {
>        std::cout <<ex->num <<"," <<ex->den<<std::endl;
>     }
>
>
> I'm not sure but what about something along these lines?
>
> const E* expected_cast(const expected<T>* y) {
>   try {
>     if (!y->valid())
>         std::rethrow_exception(y->exception_ptr());
>   } catch (const E& object) {
>      return &obj;
>   } catch (...) {
>   }
>   return nullptr;
> }
>
> Is there any lifetime issue here?
Yes, the lifetime of object referenced by the variable object is limited=20
to the try_catch block.
This is why I'm requesting a specific function.

Vicente

--=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--------------050805000700070007040300
Content-Type: text/html; charset=ISO-8859-1

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Le 06/01/14 16:33, Cassio Neri a
      &eacute;crit&nbsp;:<br>
    </div>
    <blockquote
      cite="mid:775b0fd7-2b3a-4667-b776-d13efe0d2fdb@isocpp.org"
      type="cite">
      <div dir="ltr"><br>
        <br>
        On Saturday, January 4, 2014 11:45:48 AM UTC, Vicente J. Botet
        Escriba wrote:
        <blockquote class="gmail_quote" style="margin: 0;margin-left:
          0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
          <div bgcolor="#FFFFFF" text="#000000"> <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;<wbr>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>
          </div>
        </blockquote>
        <div><br>
          I'm not sure but what about something along these lines?<br>
          <br>
          const E* expected_cast(const expected&lt;T&gt;* y) {<br>
          &nbsp; try {<br>
          &nbsp;&nbsp;&nbsp; if (!y-&gt;valid())<br>
          &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::rethrow_exception(y-&gt;exception_ptr());<br>
          &nbsp; } catch (const E&amp; object) {<br>
          &nbsp; &nbsp;&nbsp; return &amp;obj;<br>
          &nbsp; } catch (...) {<br>
          &nbsp; }<br>
          &nbsp; return nullptr;<br>
          }<br>
          <br>
          Is there any lifetime issue here? </div>
      </div>
    </blockquote>
    Yes, the lifetime of object referenced by the variable object is
    limited to the try_catch block.<br>
    This is why I'm requesting a specific function.<br>
    <br>
    Vicente<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 />

--------------050805000700070007040300--

.