Topic: Catch block for multiple exceptions
Author: david.bolvansky@gmail.com
Date: Tue, 1 Aug 2017 10:04:21 -0700 (PDT)
Raw View
------=_Part_2652_308856715.1501607061056
Content-Type: multipart/alternative;
boundary="----=_Part_2653_1000255546.1501607061056"
------=_Part_2653_1000255546.1501607061056
Content-Type: text/plain; charset="UTF-8"
If you need to handle multiple exceptions you write catch block per every
exception.
Example:
try {
...
} catch (exceptionA e) {
// handle expetionA
f();
}
} catch (exceptionB e) {
// handle exceptionB
f();
}
} catch (exceptionC e) {
// handle exceptionC
f();
}
} catch (exceptionD e) {
// handle exceptionD
g();
}
If e.g. exception A, B, C could be handled via the same logic (e.g function
"f"), we are copy-pasting exception-handling code (callinf f() in this
case) in particular catch blocks.
To avoid that, proposed improvment could be:
try {
...
} catch (exceptionA, exceptionB, exceptionC) {
// handle exception (does not matter whether exception A, B or C - we
have same handling code for them)
f();
}
} catch (exceptionD e) {
// handle exceptionD
g();
}
With the instance of one of those exceptions:
catch (exceptionA, exceptionB, exceptionC e) {
f(e);
}
--
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/effe744d-f832-42c7-9b2a-ef31551067d0%40isocpp.org.
------=_Part_2653_1000255546.1501607061056
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">If you need to handle multiple exceptions you write catch =
block per every exception.<div><br></div><div>Example:<br><div><br></div><d=
iv class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bor=
der-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word=
-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprin=
t"><span style=3D"color: #008;" class=3D"styled-by-prettify">try</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">catch</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>exceptionA e</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0=
</span><span style=3D"color: #800;" class=3D"styled-by-prettify">// handle =
expetionA</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>=C2=A0 =C2=A0 =C2=A0f</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=
<br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">catch</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">exceptionB e</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">// handle exceptionB</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0f</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br><br><br></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">catch</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">exceptionC e</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0</span><span =
style=3D"color: #800;" class=3D"styled-by-prettify">// handle exceptionC</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 =C2=A0f</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br></span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">catch</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">exceptionD e</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 =C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-pre=
ttify">// handle exceptionD</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0g</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br></span></div></code></div><div><br><br></div><div><br></d=
iv><div>If e.g. exception A, B, C could be handled via the same logic (e.g =
function "f"), we are copy-pasting exception-handling code (calli=
nf f() in this case) in particular catch blocks.</div><div><br></div><div><=
br></div><div>To avoid that, proposed improvment could be:</div><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">try</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">catch</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">exceptionA</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> exceptionB</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> exceptionC</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #=
800;" class=3D"styled-by-prettify">// handle exception (does not matter whe=
ther exception A, B or C - we have same handling code for them)</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=
=A0f</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">catch</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">exceptionD e</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-prettify">// h=
andle exceptionD</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 =C2=A0g</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br><br><br></span></div></code></div><div><br></div><div><br></div><div>Wit=
h the instance of one of =C2=A0those exceptions:</div><div><div class=3D"pr=
ettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb=
(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-w=
ord;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">catch</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">exceptionA</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> exceptionB</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> exceptionC e</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">f</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">e</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span></div></code></div><br><br><br></div></div>=
</div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/effe744d-f832-42c7-9b2a-ef31551067d0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/effe744d-f832-42c7-9b2a-ef31551067d0=
%40isocpp.org</a>.<br />
------=_Part_2653_1000255546.1501607061056--
------=_Part_2652_308856715.1501607061056--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 1 Aug 2017 10:50:47 -0700 (PDT)
Raw View
------=_Part_5163_2138062996.1501609847427
Content-Type: multipart/alternative;
boundary="----=_Part_5164_37121966.1501609847428"
------=_Part_5164_37121966.1501609847428
Content-Type: text/plain; charset="UTF-8"
On Tuesday, August 1, 2017 at 1:04:21 PM UTC-4, david.b...@gmail.com wrote:
>
> If you need to handle multiple exceptions you write catch block per every
> exception.
>
> Example:
>
> try {
> ...
> } catch (exceptionA e) {
> // handle expetionA
> f();
> }
>
>
> } catch (exceptionB e) {
> // handle exceptionB
> f();
> }
>
>
> } catch (exceptionC e) {
> // handle exceptionC
> f();
> }
>
>
> } catch (exceptionD e) {
> // handle exceptionD
> g();
> }
>
>
>
>
> If e.g. exception A, B, C could be handled via the same logic (e.g
> function "f"), we are copy-pasting exception-handling code (callinf f() in
> this case) in particular catch blocks.
>
>
> To avoid that, proposed improvment could be:
>
>
> try {
> ...
> } catch (exceptionA, exceptionB, exceptionC) {
> // handle exception (does not matter whether exception A, B or C -
> we have same handling code for them)
> f();
> }
>
> } catch (exceptionD e) {
> // handle exceptionD
> g();
> }
>
>
>
>
So, here's a question: why would you have this circumstance? That is, 3
completely unrelated exception types require the exact same handling code
(to the point where they don't even use the exception object itself), while
simultaneously there is a fourth exception type which requires different
handling code. What could possibly cause such a thing?
Decent use of RAII eliminates 99% of `catch` statements for the purpose of
cleanup. That leaves behind work based on the specific kind of exception. I
could imagine a database throwing a transaction failure exception as well
as an out of memory exception. You need different code to handle those
(assuming you want to handle OOM at all).
But why would such a database have multiple unrelated transaction failure
exception types? Or multiple unrelated memory exception types? Generally
speaking, we allow users to catch related exceptions in the same statement
by using inheritance from a common exception type. If a database had
multiple kinds of transaction failures, they should all be derived from a
root "transaction failure" exception.
So I find the use case to be dubious. Can you provide a more concrete, less
hypothetical example?
> With the instance of one of those exceptions:
> catch (exceptionA, exceptionB, exceptionC e) {
> f(e);
> }
>
>
That's rather more disconcerting. You now need code to be validated against
3 unrelated types. Effectively, you're instantiating a template, but only
from a certain set of types.
I don't much care for that either.
--
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/deaedeb0-a699-49e9-826a-c41e674902c0%40isocpp.org.
------=_Part_5164_37121966.1501609847428
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, August 1, 2017 at 1:04:21 PM UTC-4, david.b...=
@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">If you need to handle multiple exceptions you write catch block per eve=
ry exception.<div><br></div><div>Example:<br><div><br></div><div style=3D"b=
ackground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style=
:solid;border-width:1px;word-wrap:break-word"><code><div><span style=3D"col=
or:#008">try</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 </span><s=
pan style=3D"color:#660">...</span><span style=3D"color:#000"><br></span><s=
pan style=3D"color:#660">}</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">catch</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">exceptionA e</span><s=
pan style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =
=C2=A0</span><span style=3D"color:#800">// handle expetionA</span><span sty=
le=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0f</span><span style=3D"color:#660=
">();</span><span style=3D"color:#000"><br></span><span style=3D"color:#660=
">}</span><span style=3D"color:#000"><br><br><br></span><span style=3D"colo=
r:#660">}</span><span style=3D"color:#000"> </span><span style=3D"color:#00=
8">catch</span><span style=3D"color:#000"> </span><span style=3D"color:#660=
">(</span><span style=3D"color:#000">exceptionB e</span><span style=3D"colo=
r:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#66=
0">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0</span><span =
style=3D"color:#800">// handle exceptionB</span><span style=3D"color:#000">=
<br>=C2=A0 =C2=A0 =C2=A0f</span><span style=3D"color:#660">();</span><span =
style=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span st=
yle=3D"color:#000"><br><br><br></span><span style=3D"color:#660">}</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">catch</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">(</span><span st=
yle=3D"color:#000">exceptionC e</span><span style=3D"color:#660">)</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span s=
tyle=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:#80=
0">// handle exceptionC</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =
=C2=A0f</span><span style=3D"color:#660">();</span><span style=3D"color:#00=
0"><br></span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
><br><br><br></span><span style=3D"color:#660">}</span><span style=3D"color=
:#000"> </span><span style=3D"color:#008">catch</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">(</span><span style=3D"color:#000"=
>exceptionD e</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000=
"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:#800">// handle excep=
tionD</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0g</span><spa=
n style=3D"color:#660">();</span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span></=
div></code></div><div><br><br></div><div><br></div><div>If e.g. exception A=
, B, C could be handled via the same logic (e.g function "f"), we=
are copy-pasting exception-handling code (callinf f() in this case) in par=
ticular catch blocks.</div><div><br></div><div><br></div><div>To avoid that=
, proposed improvment could be:</div><div style=3D"background-color:rgb(250=
,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px=
;word-wrap:break-word"><code><div><span style=3D"color:#000"><br><br></span=
><span style=3D"color:#008">try</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 =C2=A0 </span><span style=3D"color:#660">...</span><span style=3D"color=
:#000"><br></span><span style=3D"color:#660">}</span><span style=3D"color:#=
000"> </span><span style=3D"color:#008">catch</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">(</span><span style=3D"color:#000">e=
xceptionA</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"> exceptionB</span><span style=3D"color:#660">,</span><span style=3D"colo=
r:#000"> exceptionC</span><span style=3D"color:#660">)</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"colo=
r:#000"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:#800">// handle=
exception (does not matter whether exception A, B or C - we have same hand=
ling code for them)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=
=A0f</span><span style=3D"color:#660">();</span><span style=3D"color:#000">=
<br></span><span style=3D"color:#660">}</span><span style=3D"color:#000"><b=
r><br></span><span style=3D"color:#660">}</span><span style=3D"color:#000">=
</span><span style=3D"color:#008">catch</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">(</span><span style=3D"color:#000">except=
ionD e</span><span style=3D"color:#660">)</span><span style=3D"color:#000">=
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:#800">// handle exceptionD<=
/span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0g</span><span styl=
e=3D"color:#660">();</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"><br><br><br></span></di=
v></code></div><div><br></div></div></div></blockquote><div><br>So, here=
9;s a question: why would you have this circumstance? That is, 3 completely=
unrelated exception types require the exact same handling code (to the poi=
nt where they don't even use the exception object itself), while simult=
aneously there is a fourth exception type which requires different handling=
code. What could possibly cause such a thing?<br><br>Decent use of RAII el=
iminates 99% of `catch` statements for the purpose of cleanup. That leaves =
behind work based on the specific kind of exception. I could imagine a data=
base throwing a transaction failure exception as well as an out of memory e=
xception. You need different code to handle those (assuming you want to han=
dle OOM at all).<br><br>But why would such a database have multiple unrelat=
ed transaction failure exception types? Or multiple unrelated memory except=
ion types? Generally speaking, we allow users to catch related exceptions i=
n the same statement by using inheritance from a common exception type. If =
a database had multiple kinds of transaction failures, they should all be d=
erived from a root "transaction failure" exception.<br><br>So I f=
ind the use case to be dubious. Can you provide a more concrete, less hypot=
hetical example?<br><br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr"><div><div></div><div><br></div><div>With the instance of o=
ne of =C2=A0those exceptions:</div><div><div style=3D"background-color:rgb(=
250,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:=
1px;word-wrap:break-word"><code><div><span style=3D"color:#008">catch</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">(</span><spa=
n style=3D"color:#000">exceptionA</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> exceptionB</span><span style=3D"color:#660">,</=
span><span style=3D"color:#000"> exceptionC e</span><span style=3D"color:#6=
60">)</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=3D"co=
lor:#000">f</span><span style=3D"color:#660">(</span><span style=3D"color:#=
000">e</span><span style=3D"color:#660">);</span><span style=3D"color:#000"=
><br></span><span style=3D"color:#660">}</span></div></code></div><br></div=
></div></div></blockquote><div><br>That's rather more disconcerting. Yo=
u now need code to be validated against 3 unrelated types. Effectively, you=
're instantiating a template, but only from a certain set of types.<br>=
<br>I don't much care for that either.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/deaedeb0-a699-49e9-826a-c41e674902c0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/deaedeb0-a699-49e9-826a-c41e674902c0=
%40isocpp.org</a>.<br />
------=_Part_5164_37121966.1501609847428--
------=_Part_5163_2138062996.1501609847427--
.
Author: Dejan Milosavljevic <dmilos@gmail.com>
Date: Wed, 2 Aug 2017 09:04:35 +0200
Raw View
--f403045f55de6a929d0555bfe0bb
Content-Type: text/plain; charset="UTF-8"
catch (exceptionA, exceptionB, exceptionC e) {
f(e);
}
Questions:
- How to know which exception invoke this catch?
- If catch was invoked by exceptionA what is the content of exceptionC?
On Tue, Aug 1, 2017 at 7:50 PM, Nicol Bolas <jmckesson@gmail.com> wrote:
> On Tuesday, August 1, 2017 at 1:04:21 PM UTC-4, david.b...@gmail.com
> wrote:
>>
>> If you need to handle multiple exceptions you write catch block per every
>> exception.
>>
>> Example:
>>
>> try {
>> ...
>> } catch (exceptionA e) {
>> // handle expetionA
>> f();
>> }
>>
>>
>> } catch (exceptionB e) {
>> // handle exceptionB
>> f();
>> }
>>
>>
>> } catch (exceptionC e) {
>> // handle exceptionC
>> f();
>> }
>>
>>
>> } catch (exceptionD e) {
>> // handle exceptionD
>> g();
>> }
>>
>>
>>
>>
>> If e.g. exception A, B, C could be handled via the same logic (e.g
>> function "f"), we are copy-pasting exception-handling code (callinf f() in
>> this case) in particular catch blocks.
>>
>>
>> To avoid that, proposed improvment could be:
>>
>>
>> try {
>> ...
>> } catch (exceptionA, exceptionB, exceptionC) {
>> // handle exception (does not matter whether exception A, B or C -
>> we have same handling code for them)
>> f();
>> }
>>
>> } catch (exceptionD e) {
>> // handle exceptionD
>> g();
>> }
>>
>>
>>
>>
> So, here's a question: why would you have this circumstance? That is, 3
> completely unrelated exception types require the exact same handling code
> (to the point where they don't even use the exception object itself), while
> simultaneously there is a fourth exception type which requires different
> handling code. What could possibly cause such a thing?
>
> Decent use of RAII eliminates 99% of `catch` statements for the purpose of
> cleanup. That leaves behind work based on the specific kind of exception. I
> could imagine a database throwing a transaction failure exception as well
> as an out of memory exception. You need different code to handle those
> (assuming you want to handle OOM at all).
>
> But why would such a database have multiple unrelated transaction failure
> exception types? Or multiple unrelated memory exception types? Generally
> speaking, we allow users to catch related exceptions in the same statement
> by using inheritance from a common exception type. If a database had
> multiple kinds of transaction failures, they should all be derived from a
> root "transaction failure" exception.
>
> So I find the use case to be dubious. Can you provide a more concrete,
> less hypothetical example?
>
>
>> With the instance of one of those exceptions:
>> catch (exceptionA, exceptionB, exceptionC e) {
>> f(e);
>> }
>>
>>
> That's rather more disconcerting. You now need code to be validated
> against 3 unrelated types. Effectively, you're instantiating a template,
> but only from a certain set of types.
>
> I don't much care for that either.
>
> --
> 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/deaedeb0-a699-49e9-
> 826a-c41e674902c0%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/deaedeb0-a699-49e9-826a-c41e674902c0%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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/CAEfefmzCWDwP2ha7UfvvPrW_56TT4DEgvwRyxWm%3D6gS_GZc7pA%40mail.gmail.com.
--f403045f55de6a929d0555bfe0bb
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><p><font face=3D"monospace,monospace">catch (exceptionA, e=
xceptionB, exceptionC e) {<br>=C2=A0=C2=A0 f(e);<br>}</font></p><p>Question=
s:</p><p>- How to know which exception invoke this catch?<br>- If catch was=
invoked by <font face=3D"monospace,monospace">exceptionA</font> what is th=
e content of <font face=3D"monospace,monospace">exceptionC</font>?</p></div=
><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Tue, Aug 1, 2=
017 at 7:50 PM, Nicol Bolas <span dir=3D"ltr"><<a href=3D"mailto:jmckess=
on@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>></span> wrote:<b=
r><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"h5">On=
Tuesday, August 1, 2017 at 1:04:21 PM UTC-4, <a href=3D"mailto:david.b...@=
gmail.com" target=3D"_blank">david.b...@gmail.com</a> wrote:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;borde=
r-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid=
"><div dir=3D"ltr">If you need to handle multiple exceptions you write catc=
h block per every exception.<div><br></div><div>Example:<br><div><br></div>=
<div style=3D"border:1px solid rgb(187,187,187);background-color:rgb(250,25=
0,250)"><code><div><span style=3D"color:rgb(0,0,136)">try</span><span style=
=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span>=
<span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0 </span><span styl=
e=3D"color:rgb(102,102,0)">...</span><span style=3D"color:rgb(0,0,0)"><br><=
/span><span style=3D"color:rgb(102,102,0)">}</span><span style=3D"color:rgb=
(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">catch</span><span style=
=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">(</span>=
<span style=3D"color:rgb(0,0,0)">exceptionA e</span><span style=3D"color:rg=
b(102,102,0)">)</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br>=C2=
=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(136,0,0)">// handle expeti=
onA</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0f</span>=
<span style=3D"color:rgb(102,102,0)">();</span><span style=3D"color:rgb(0,0=
,0)"><br></span><span style=3D"color:rgb(102,102,0)">}</span><span style=3D=
"color:rgb(0,0,0)"><br><br><br></span><span style=3D"color:rgb(102,102,0)">=
}</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0=
,0,136)">catch</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">exceptio=
nB e</span><span style=3D"color:rgb(102,102,0)">)</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span st=
yle=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"colo=
r:rgb(136,0,0)">// handle exceptionB</span><span style=3D"color:rgb(0,0,0)"=
><br>=C2=A0 =C2=A0 =C2=A0f</span><span style=3D"color:rgb(102,102,0)">();</=
span><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(1=
02,102,0)">}</span><span style=3D"color:rgb(0,0,0)"><br><br><br></span><spa=
n style=3D"color:rgb(102,102,0)">}</span><span style=3D"color:rgb(0,0,0)"> =
</span><span style=3D"color:rgb(0,0,136)">catch</span><span style=3D"color:=
rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">(</span><span styl=
e=3D"color:rgb(0,0,0)">exceptionC e</span><span style=3D"color:rgb(102,102,=
0)">)</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =
=C2=A0</span><span style=3D"color:rgb(136,0,0)">// handle exceptionC</span>=
<span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0f</span><span styl=
e=3D"color:rgb(102,102,0)">();</span><span style=3D"color:rgb(0,0,0)"><br><=
/span><span style=3D"color:rgb(102,102,0)">}</span><span style=3D"color:rgb=
(0,0,0)"><br><br><br></span><span style=3D"color:rgb(102,102,0)">}</span><s=
pan style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">c=
atch</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rg=
b(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">exceptionD e</span><=
span style=3D"color:rgb(102,102,0)">)</span><span style=3D"color:rgb(0,0,0)=
"> </span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color=
:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(136,0,=
0)">// handle exceptionD</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =
=C2=A0 =C2=A0g</span><span style=3D"color:rgb(102,102,0)">();</span><span s=
tyle=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(102,102,0)">}=
</span><span style=3D"color:rgb(0,0,0)"><br><br></span></div></code></div><=
div><br><br></div><div><br></div><div>If e.g. exception A, B, C could be ha=
ndled via the same logic (e.g function "f"), we are copy-pasting =
exception-handling code (callinf f() in this case) in particular catch bloc=
ks.</div><div><br></div><div><br></div><div>To avoid that, proposed improvm=
ent could be:</div><div style=3D"border:1px solid rgb(187,187,187);backgrou=
nd-color:rgb(250,250,250)"><code><div><span style=3D"color:rgb(0,0,0)"><br>=
<br></span><span style=3D"color:rgb(0,0,136)">try</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span st=
yle=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"col=
or:rgb(102,102,0)">...</span><span style=3D"color:rgb(0,0,0)"><br></span><s=
pan style=3D"color:rgb(102,102,0)">}</span><span style=3D"color:rgb(0,0,0)"=
> </span><span style=3D"color:rgb(0,0,136)">catch</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">(</span><span st=
yle=3D"color:rgb(0,0,0)">exceptionA</span><span style=3D"color:rgb(102,102,=
0)">,</span><span style=3D"color:rgb(0,0,0)"> exceptionB</span><span style=
=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0)"> excepti=
onC</span><span style=3D"color:rgb(102,102,0)">)</span><span style=3D"color=
:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span sty=
le=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color=
:rgb(136,0,0)">// handle exception (does not matter whether exception A, B =
or C - we have same handling code for them)</span><span style=3D"color:rgb(=
0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0f</span><span style=3D"color:rgb(102,102,0)=
">();</span><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"colo=
r:rgb(102,102,0)">}</span><span style=3D"color:rgb(0,0,0)"><br><br></span><=
span style=3D"color:rgb(102,102,0)">}</span><span style=3D"color:rgb(0,0,0)=
"> </span><span style=3D"color:rgb(0,0,136)">catch</span><span style=3D"col=
or:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">(</span><span s=
tyle=3D"color:rgb(0,0,0)">exceptionD e</span><span style=3D"color:rgb(102,1=
02,0)">)</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"colo=
r:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=
=A0 =C2=A0</span><span style=3D"color:rgb(136,0,0)">// handle exceptionD</s=
pan><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0g</span><span =
style=3D"color:rgb(102,102,0)">();</span><span style=3D"color:rgb(0,0,0)"><=
br></span><span style=3D"color:rgb(102,102,0)">}</span><span style=3D"color=
:rgb(0,0,0)"><br><br><br></span></div></code></div><div><br></div></div></d=
iv></blockquote></div></div><div><br>So, here's a question: why would y=
ou have this circumstance? That is, 3 completely unrelated exception types =
require the exact same handling code (to the point where they don't eve=
n use the exception object itself), while simultaneously there is a fourth =
exception type which requires different handling code. What could possibly =
cause such a thing?<br><br>Decent use of RAII eliminates 99% of `catch` sta=
tements for the purpose of cleanup. That leaves behind work based on the sp=
ecific kind of exception. I could imagine a database throwing a transaction=
failure exception as well as an out of memory exception. You need differen=
t code to handle those (assuming you want to handle OOM at all).<br><br>But=
why would such a database have multiple unrelated transaction failure exce=
ption types? Or multiple unrelated memory exception types? Generally speaki=
ng, we allow users to catch related exceptions in the same statement by usi=
ng inheritance from a common exception type. If a database had multiple kin=
ds of transaction failures, they should all be derived from a root "tr=
ansaction failure" exception.<br><br>So I find the use case to be dubi=
ous. Can you provide a more concrete, less hypothetical example?<br><br></d=
iv><span><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px=
;border-left-style:solid"><div dir=3D"ltr"><div><div></div><div><br></div><=
div>With the instance of one of =C2=A0those exceptions:</div><div><div styl=
e=3D"border:1px solid rgb(187,187,187);background-color:rgb(250,250,250)"><=
code><div><span style=3D"color:rgb(0,0,136)">catch</span><span style=3D"col=
or:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">(</span><span s=
tyle=3D"color:rgb(0,0,0)">exceptionA</span><span style=3D"color:rgb(102,102=
,0)">,</span><span style=3D"color:rgb(0,0,0)"> exceptionB</span><span style=
=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0)"> excepti=
onC e</span><span style=3D"color:rgb(102,102,0)">)</span><span style=3D"col=
or:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span s=
tyle=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0</span><span style=3D"color:rgb(=
0,0,0)">f</span><span style=3D"color:rgb(102,102,0)">(</span><span style=3D=
"color:rgb(0,0,0)">e</span><span style=3D"color:rgb(102,102,0)">);</span><s=
pan style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(102,102,=
0)">}</span></div></code></div><br></div></div></div></blockquote></span><d=
iv><br>That's rather more disconcerting. You now need code to be valida=
ted against 3 unrelated types. Effectively, you're instantiating a temp=
late, but only from a certain set of types.<br><br>I don't much care fo=
r that either.<br></div></div><span>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br></span>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/deaedeb0-a699-49e9-826a-c41e674902c0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/deae=
deb0-a699-49e9-<wbr>826a-c41e674902c0%40isocpp.org</a><wbr>.<br>
</blockquote></div><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CAEfefmzCWDwP2ha7UfvvPrW_56TT4DEgvwRy=
xWm%3D6gS_GZc7pA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAEfefmzCWDwP2h=
a7UfvvPrW_56TT4DEgvwRyxWm%3D6gS_GZc7pA%40mail.gmail.com</a>.<br />
--f403045f55de6a929d0555bfe0bb--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 02 Aug 2017 00:12:40 -0700
Raw View
On Wednesday, 2 August 2017 00:04:35 PDT Dejan Milosavljevic wrote:
> catch (exceptionA, exceptionB, exceptionC e) {
> f(e);
> }
>
> Questions:
>
> - How to know which exception invoke this catch?
> - If catch was invoked by exceptionA what is the content of exceptionC?
If we adopt this syntax, then the above cannot be well-formed: if catching
multiple types, then no variable names must be specified.
And how to know which one invoked? You don't. If you wanted to know if it was
exceptionA, you'd add a catch block for it.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/4126837.jZlGhgVnua%40tjmaciei-mobl1.
.
Author: Barry Revzin <barry.revzin@gmail.com>
Date: Wed, 2 Aug 2017 05:47:38 -0700 (PDT)
Raw View
------=_Part_1426_1562684480.1501678058997
Content-Type: multipart/alternative;
boundary="----=_Part_1427_272495081.1501678058997"
------=_Part_1427_272495081.1501678058997
Content-Type: text/plain; charset="UTF-8"
>
> And how to know which one invoked? You don't. If you wanted to know if it
> was
> exceptionA, you'd add a catch block for it.
>
You'd almost want something like:
catch (variant<exceptionA&, exceptionB&, exceptionC&> e) {
visit([](auto& e){ f(e); }, e);
}
Granted that's a fairly large change to how the catch mechanics currently
work...
--
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/d14636de-fb57-47b3-8666-7976ccdb6fe8%40isocpp.org.
------=_Part_1427_272495081.1501678058997
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">And how to kn=
ow which one invoked? You don't. If you wanted to know if it was=20
<br>exceptionA, you'd add a catch block for it. =C2=A0</blockquote><blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;">=C2=A0<br></blockquote><div><br></=
div><div>You'd almost want something like:</div><div><br></div><div><di=
v class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bord=
er-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-=
wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint=
"><font color=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">catch</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">variant</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">exceptionA</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&,</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> exceptionB</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> exceptionC</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> e</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 visit</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">([](</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">auto</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> e</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
){</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">e</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">},</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> e</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</spa=
n></font></div></code></div><br>Granted that's a fairly large change to=
how the catch mechanics currently work...=C2=A0</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/d14636de-fb57-47b3-8666-7976ccdb6fe8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d14636de-fb57-47b3-8666-7976ccdb6fe8=
%40isocpp.org</a>.<br />
------=_Part_1427_272495081.1501678058997--
------=_Part_1426_1562684480.1501678058997--
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Wed, 2 Aug 2017 09:38:26 -0400
Raw View
On 2017-08-02 08:47, Barry Revzin wrote:
>> And how to know which one invoked? You don't. If you wanted to know if it
>> was exceptionA, you'd add a catch block for it.
>
> You'd almost want something like:
>
> catch (variant<exceptionA&, exceptionB&, exceptionC&> e) {
> visit([](auto& e){ f(e); }, e);
> }
catch (exceptionA, exceptionB, exceptionC e) {
if constexpr (std::is_same_type_t<decltype(e), exceptionA>) {
...do something with exceptionA...
}
}
IOW, implement such blocks sort of like templates; write the code once,
but the compiler internally converts it to separate catch-blocks with
the same bodies.
--
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/d58143f8-c128-3745-b835-1e04a5760d0d%40gmail.com.
.
Author: Ricardo Fabiano de Andrade <ricardofabianodeandrade@gmail.com>
Date: Wed, 2 Aug 2017 13:05:30 -0500
Raw View
--001a114eccbc06e71a0555c91c88
Content-Type: text/plain; charset="UTF-8"
Hum, a template... bikeshedding an alternate syntax:
catch<exceptionA, exceptionB, exceptionC>(auto& e) {
... do something
}
On Wed, Aug 2, 2017 at 8:38 AM, Matthew Woehlke <mwoehlke.floss@gmail.com>
wrote:
> On 2017-08-02 08:47, Barry Revzin wrote:
> >> And how to know which one invoked? You don't. If you wanted to know if
> it
> >> was exceptionA, you'd add a catch block for it.
> >
> > You'd almost want something like:
> >
> > catch (variant<exceptionA&, exceptionB&, exceptionC&> e) {
> > visit([](auto& e){ f(e); }, e);
> > }
>
> catch (exceptionA, exceptionB, exceptionC e) {
> if constexpr (std::is_same_type_t<decltype(e), exceptionA>) {
> ...do something with exceptionA...
> }
> }
>
> IOW, implement such blocks sort of like templates; write the code once,
> but the compiler internally converts it to separate catch-blocks with
> the same bodies.
>
> --
> 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/d58143f8-c128-3745-
> b835-1e04a5760d0d%40gmail.com.
>
--
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/CA%2BfGSbMB3%3DH4hetWu3GFPzUskLP_sh0Q%3DQ4oxsUsZ6ci-jrpxg%40mail.gmail.com.
--001a114eccbc06e71a0555c91c88
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hum, a template... bikeshedding an alternate syntax:<div><=
br></div><div>catch<exceptionA, exceptionB, exceptionC>(auto& e) =
{</div><div>=C2=A0... do something</div><div>}</div></div><div class=3D"gma=
il_extra"><br><div class=3D"gmail_quote">On Wed, Aug 2, 2017 at 8:38 AM, Ma=
tthew Woehlke <span dir=3D"ltr"><<a href=3D"mailto:mwoehlke.floss@gmail.=
com" target=3D"_blank">mwoehlke.floss@gmail.com</a>></span> wrote:<br><b=
lockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px =
#ccc solid;padding-left:1ex">On 2017-08-02 08:47, Barry Revzin wrote:<br>
>> And how to know which one invoked? You don't. If you wanted to=
know if it<br>
>> was exceptionA, you'd add a catch block for it.<br>
><br>
> You'd almost want something like:<br>
><br>
> catch (variant<exceptionA&, exceptionB&, exceptionC&>=
; e) {<br>
>=C2=A0 =C2=A0 =C2=A0visit([](auto& e){ f(e); }, e);<br>
> }<br>
<br>
=C2=A0 catch (exceptionA, exceptionB, exceptionC e) {<br>
=C2=A0 =C2=A0 if constexpr (std::is_same_type_t<decltype(<wbr>e), except=
ionA>) {<br>
=C2=A0 =C2=A0 =C2=A0 ...do something with exceptionA...<br>
=C2=A0 =C2=A0 }<br>
=C2=A0 }<br>
<br>
IOW, implement such blocks sort of like templates; write the code once,<br>
but the compiler internally converts it to separate catch-blocks with<br>
the same bodies.<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
--<br>
Matthew<br>
<br>
--<br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-propo=
sals+unsubscribe@<wbr>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/d58143f8-c128-3745-b835-1e04a5760d0d%=
40gmail.com" rel=3D"noreferrer" target=3D"_blank">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/d58143f8-c128-3745-<wbr>b835-=
1e04a5760d0d%40gmail.com</a>.<br>
</font></span></blockquote></div><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CA%2BfGSbMB3%3DH4hetWu3GFPzUskLP_sh0Q=
%3DQ4oxsUsZ6ci-jrpxg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CA%2BfGSbMB=
3%3DH4hetWu3GFPzUskLP_sh0Q%3DQ4oxsUsZ6ci-jrpxg%40mail.gmail.com</a>.<br />
--001a114eccbc06e71a0555c91c88--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 2 Aug 2017 21:40:31 +0300
Raw View
On 2 August 2017 at 21:05, Ricardo Fabiano de Andrade
<ricardofabianodeandrade@gmail.com> wrote:
> Hum, a template... bikeshedding an alternate syntax:
>
> catch<exceptionA, exceptionB, exceptionC>(auto& e) {
> ... do something
> }
Boo hiss. Let's just write a solution with the toys C++17 gives us.
Put handler_helper into
a local library of yours and use it like I use it in main:
#include <exception>
#include <iostream>
struct ExcA
{
void common() const {std::cout << "common in ExcA" << std::endl;}
};
struct ExcB
{
void common() const {std::cout << "common in ExcB" << std::endl;}
};
struct ExcC
{
void common() const {std::cout << "common in ExcC" << std::endl;}
};
template <class... Exceptions, class Handler> void handler_helper(Handler h)
{
([&](auto&& a) {
try {
throw;
} catch (const decltype(*a)& exc) {
h(exc);
} catch (...) {
}
}(std::add_pointer_t<Exceptions>()),...);
}
int main()
{
try {
//throw ExcA();
//throw ExcB();
throw ExcC();
} catch (...) {
handler_helper<ExcA, ExcB, ExcC>([](auto&& c) {
c.common();
});
}
}
--
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/CAFk2RUbdEQMQB4qLCDeaHeF0Q4ntbZG7-Cuf0X2G8d5%2BDpf1Pw%40mail.gmail.com.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 2 Aug 2017 11:47:28 -0700 (PDT)
Raw View
------=_Part_3380_1459456279.1501699649030
Content-Type: multipart/alternative;
boundary="----=_Part_3381_1107108792.1501699649030"
------=_Part_3381_1107108792.1501699649030
Content-Type: text/plain; charset="UTF-8"
On Wednesday, August 2, 2017 at 2:40:35 PM UTC-4, Ville Voutilainen wrote:
>
> On 2 August 2017 at 21:05, Ricardo Fabiano de Andrade
> <ricardofabi...@gmail.com <javascript:>> wrote:
> > Hum, a template... bikeshedding an alternate syntax:
> >
> > catch<exceptionA, exceptionB, exceptionC>(auto& e) {
> > ... do something
> > }
>
>
> Boo hiss. Let's just write a solution with the toys C++17 gives us.
>
That is a truly hideous stream of code. But I imagine that this situation
is so rare that a "hideous stream of code" is probably not a terrible idea
for a solution.
However, I think a small library feature could help make it less painful.
Right now, we have `current_exception`, which gives us an `exception_ptr`,
which is completely type-erased. We could give `exception_ptr` a way to
un-erase the type. After all, the implementation has to have that type
somewhere, since we can throw and re-catch it.
So perhaps an `any_cast`-like mechanism, that returns either `nullptr` or a
pointer to the exception object. Only it should work as if it were a
`dynamic_cast`. Then, we could implement an `exception_visitor` that takes
a sequence of types and tries them, in order.
--
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/aec5f733-d43e-4d75-b001-0a0e9d49217f%40isocpp.org.
------=_Part_3381_1107108792.1501699649030
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, August 2, 2017 at 2:40:35 PM UTC-4, =
Ville Voutilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2 A=
ugust 2017 at 21:05, Ricardo Fabiano de Andrade
<br><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
hISI7gbZBQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">ricardofabi...@<wbr>gmail.com</a>> wrote:
<br>> Hum, a template... bikeshedding an alternate syntax:
<br>>
<br>> catch<exceptionA, exceptionB, exceptionC>(auto& e) {
<br>> =C2=A0... do something
<br>> }
<br>
<br>
<br>Boo hiss. Let's just write a solution with the toys C++17 gives us.
<br></blockquote><div><br>That is a truly hideous stream of code. But I ima=
gine that this situation is so rare that a "hideous stream of code&quo=
t; is probably not a terrible idea for a solution.<br><br>However, I think =
a small library feature could help make it less painful. Right now, we have=
`current_exception`, which gives us an `exception_ptr`, which is completel=
y type-erased. We could give `exception_ptr` a way to un-erase the type. Af=
ter all, the implementation has to have that type somewhere, since we can t=
hrow and re-catch it.<br><br>So perhaps an `any_cast`-like mechanism, that =
returns either `nullptr` or a pointer to the exception object. Only it shou=
ld work as if it were a `dynamic_cast`. Then, we could implement an `except=
ion_visitor` that takes a sequence of types and tries them, in order.</div>=
</div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/aec5f733-d43e-4d75-b001-0a0e9d49217f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/aec5f733-d43e-4d75-b001-0a0e9d49217f=
%40isocpp.org</a>.<br />
------=_Part_3381_1107108792.1501699649030--
------=_Part_3380_1459456279.1501699649030--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 2 Aug 2017 21:53:49 +0300
Raw View
On 2 August 2017 at 21:47, Nicol Bolas <jmckesson@gmail.com> wrote:
>> Boo hiss. Let's just write a solution with the toys C++17 gives us.
> That is a truly hideous stream of code. But I imagine that this situation is
> so rare that a "hideous stream of code" is probably not a terrible idea for
> a solution.
If you want, you can entertain the idea of putting handler_helper into
the standard library.
Then that "hideous stream of code" boils down to
} catch (...) {
handler_helper<ExcA, ExcB, ExcC>([](auto&& c) {
c.common();
});
}
And nobody's forcing you to use a polylambda there.
--
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/CAFk2RUZXst_zeNn2Taah_SHBbNOrOD655FLAw0JjvTfyazNGLw%40mail.gmail.com.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 2 Aug 2017 22:07:00 +0300
Raw View
On 2 August 2017 at 21:47, Nicol Bolas <jmckesson@gmail.com> wrote:
> However, I think a small library feature could help make it less painful.
> Right now, we have `current_exception`, which gives us an `exception_ptr`,
> which is completely type-erased. We could give `exception_ptr` a way to
> un-erase the type. After all, the implementation has to have that type
> somewhere, since we can throw and re-catch it.
>
> So perhaps an `any_cast`-like mechanism, that returns either `nullptr` or a
> pointer to the exception object. Only it should work as if it were a
> `dynamic_cast`. Then, we could implement an `exception_visitor` that takes a
> sequence of types and tries them, in order.
The ability to do an any_cast on an exception_ptr would indeed be
nice. I'll see what I can
do. There's a chance that adding such a beast isn't particularly hard
implementation-wise.
--
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/CAFk2RUbmCYrr8eSKDHq6GDV-VhwPZoPM07Je6r5VPugEhrfpig%40mail.gmail.com.
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Wed, 2 Aug 2017 13:05:33 -0700 (PDT)
Raw View
------=_Part_6499_559883321.1501704333569
Content-Type: multipart/alternative;
boundary="----=_Part_6500_271610059.1501704333570"
------=_Part_6500_271610059.1501704333570
Content-Type: text/plain; charset="UTF-8"
On Wednesday, 2 August 2017 20:07:03 UTC+1, Ville Voutilainen wrote:
>
> On 2 August 2017 at 21:47, Nicol Bolas <jmck...@gmail.com <javascript:>>
> wrote:
> > However, I think a small library feature could help make it less
> painful.
> > Right now, we have `current_exception`, which gives us an
> `exception_ptr`,
> > which is completely type-erased. We could give `exception_ptr` a way to
> > un-erase the type. After all, the implementation has to have that type
> > somewhere, since we can throw and re-catch it.
> >
> > So perhaps an `any_cast`-like mechanism, that returns either `nullptr`
> or a
> > pointer to the exception object. Only it should work as if it were a
> > `dynamic_cast`. Then, we could implement an `exception_visitor` that
> takes a
> > sequence of types and tries them, in order.
>
> The ability to do an any_cast on an exception_ptr would indeed be
> nice. I'll see what I can
> do. There's a chance that adding such a beast isn't particularly hard
> implementation-wise.
>
For libstdc++ it's trivial:
template<class target>
target_type* exception_cast(exception_ptr& ep, bool exact = false) {
void* p = ep._M_get();
std::typeinfo target_type = typeid(target), exc_type = ep.
__cxa_exception_type();
return (exact ? target_type == exc_type : target_type.__do_catch(
exc_type, &p, 1)) ?
static_cast<target*>(p) :
nullptr;
}
I suppose MSVC might require a bit more work though. I remember when I last
looked at Windows exception handling (trying to peek at the typeid of an
unknown exception, no __cxa_exception_type there) it got hairy pretty fast.
--
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/f85a2e67-4d76-4dac-9e45-a560e3e8872f%40isocpp.org.
------=_Part_6500_271610059.1501704333570
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, 2 August 2017 20:07:03 UTC+1, Ville Voutilai=
nen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2 August 2017 at=
21:47, Nicol Bolas <<a href=3D"javascript:" target=3D"_blank" gdf-obfus=
cated-mailto=3D"fEsDtXjaBQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&=
#39;javascript:';return true;" onclick=3D"this.href=3D'javascript:&=
#39;;return true;">jmck...@gmail.com</a>> wrote:
<br>> However, I think a small library feature could help make it less p=
ainful.
<br>> Right now, we have `current_exception`, which gives us an `excepti=
on_ptr`,
<br>> which is completely type-erased. We could give `exception_ptr` a w=
ay to
<br>> un-erase the type. After all, the implementation has to have that =
type
<br>> somewhere, since we can throw and re-catch it.
<br>>
<br>> So perhaps an `any_cast`-like mechanism, that returns either `null=
ptr` or a
<br>> pointer to the exception object. Only it should work as if it were=
a
<br>> `dynamic_cast`. Then, we could implement an `exception_visitor` th=
at takes a
<br>> sequence of types and tries them, in order.
<br>
<br>The ability to do an any_cast on an exception_ptr would indeed be
<br>nice. I'll see what I can
<br>do. There's a chance that adding such a beast isn't particularl=
y hard
<br>implementation-wise.
<br></blockquote><div><br></div><div>For libstdc++ it's trivial:</div><=
div><br></div><div class=3D"prettyprint" style=3D"background-color: rgb(250=
, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-=
width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> target</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">></span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>target_type</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> exception_cast</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">exception_ptr</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> ep</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">b=
ool</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> exact =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">false</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">void</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> p </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ep<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">_M_get</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">typeinfo target_type </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">typeid</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">target</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">),</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> exc_type </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> ep</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">__cxa_=
exception_type</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">exact </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">?</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> target_type </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> exc_type </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> target_type</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">__do_catch</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">exc_type</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>p</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #066;" class=3D"styled-by-prettify">1</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">))</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">?</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">static_cast</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">target</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">*>(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">p</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">nullptr</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span=
></div></code></div></code></div><div><br></div><div>I suppose MSVC might r=
equire a bit more work though. I remember when I last looked at Windows exc=
eption handling (trying to peek at the typeid of an unknown exception, no _=
_cxa_exception_type there) it got hairy pretty fast.</div><div><br></div></=
div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/f85a2e67-4d76-4dac-9e45-a560e3e8872f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f85a2e67-4d76-4dac-9e45-a560e3e8872f=
%40isocpp.org</a>.<br />
------=_Part_6500_271610059.1501704333570--
------=_Part_6499_559883321.1501704333569--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Wed, 2 Aug 2017 15:56:38 -0700 (PDT)
Raw View
------=_Part_6400_1396982999.1501714598251
Content-Type: multipart/alternative;
boundary="----=_Part_6401_1807263504.1501714598251"
------=_Part_6401_1807263504.1501714598251
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Wednesday, August 2, 2017 at 11:40:35 AM UTC-7, Ville Voutilainen wrote:
>
> On 2 August 2017 at 21:05, Ricardo Fabiano de Andrade=20
> <ricardofabi...@gmail.com <javascript:>> wrote:=20
> > Hum, a template... bikeshedding an alternate syntax:=20
> >=20
> > catch<exceptionA, exceptionB, exceptionC>(auto& e) {=20
> > ... do something=20
> > }=20
>
>
> Boo hiss. Let's just write a solution with the toys C++17 gives us.
>
FYI, this exact puzzle (variadic "catch") was discussed in the=20
#meta_programming Slack channel on June 30th; participants were Vittorio=20
Romeo, Barry Revzin, Eric Niebler, Peter Dimov, and myself (belatedly). My=
=20
solution is here <https://wandbox.org/permlink/egm66nYboBjo0May>. Its punch=
=20
line is:
try {
throw Derived(); // this is just a placeholder for some code=
=20
that might throw
} catch (...) {
variant_catch<const Derived&, const Base&>([](auto&& e) {
printf("caught %s (%s)\n", typeid(e).name(),=20
__PRETTY_FUNCTION__);
});
}
but with the caveat that this signature (also provided at the Wandbox link=
=20
above) will be more performant (not that we care about the performance of=
=20
the exceptional path, of course):
variant_catch<const Derived&, const Base&>([&]() {
throw Derived(); // this is just a placeholder for some code that=
=20
might throw
}, [](auto&& e) {
printf("caught %s (%s)\n", typeid(e).name(), __PRETTY_FUNCTION__);
});
HTH,
=E2=80=93Arthur
--=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/54580edb-4a76-4241-b5c8-19ccbc1a562e%40isocpp.or=
g.
------=_Part_6401_1807263504.1501714598251
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, August 2, 2017 at 11:40:35 AM UTC-7, Ville V=
outilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2 August 2=
017 at 21:05, Ricardo Fabiano de Andrade
<br><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
hISI7gbZBQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">ricardofabi...@<wbr>gmail.com</a>> wrote:
<br>> Hum, a template... bikeshedding an alternate syntax:
<br>>
<br>> catch<exceptionA, exceptionB, exceptionC>(auto& e) {
<br>> =C2=A0... do something
<br>> }
<br>
<br>
<br>Boo hiss. Let's just write a solution with the toys C++17 gives us.=
<br></blockquote><div><br></div><div>FYI, this exact puzzle (variadic "=
;catch") was discussed in the #meta_programming Slack channel on June =
30th; participants were Vittorio Romeo, Barry Revzin, Eric Niebler, Peter D=
imov, and myself (belatedly). My solution is <a href=3D"https://wandbox.org=
/permlink/egm66nYboBjo0May">here</a>. Its punch line is:</div><div><br></di=
v><div><div><font face=3D"courier new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 try {</font></div><div><font face=3D"courier new, monospace">=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 throw Derived();</font><span style=3D"font-=
family: 'courier new', monospace;">=C2=A0</span><span style=3D"font=
-family: 'courier new', monospace;">=C2=A0// this is just a placeho=
lder for some code that might throw</span></div><div><font face=3D"courier =
new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 } catch (...) {</font></div><di=
v><font face=3D"courier new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 variant_catch<const Derived&, const Base&>([](auto&=
;& e) {</font></div><div><font face=3D"courier new, monospace">=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("caught %s (%s=
)\n", typeid(e).name(), __PRETTY_FUNCTION__);</font></div><div><font f=
ace=3D"courier new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 })=
;<br></font></div><div><font face=3D"courier new, monospace">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 }</font></div></div><div><br></div><div>but with the caveat t=
hat this signature (also provided at the Wandbox link above) will be more p=
erformant (not that we care about the performance of the exceptional path, =
of course):</div><div><br></div><div><div><font face=3D"courier new, monosp=
ace">=C2=A0 =C2=A0 variant_catch<const Derived&, const Base&>=
([&]() {</font></div><div><font face=3D"courier new, monospace">=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 throw Derived(); =C2=A0// this is just a placeholder f=
or some code that might throw</font></div><div><font face=3D"courier new, m=
onospace">=C2=A0 =C2=A0 }, [](auto&& e) {</font></div><div><font fa=
ce=3D"courier new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("caug=
ht %s (%s)\n", typeid(e).name(), __PRETTY_FUNCTION__);</font></div><di=
v><font face=3D"courier new, monospace">=C2=A0 =C2=A0 });</font></div></div=
><div><br></div><div>HTH,</div><div>=E2=80=93Arthur</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/54580edb-4a76-4241-b5c8-19ccbc1a562e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/54580edb-4a76-4241-b5c8-19ccbc1a562e=
%40isocpp.org</a>.<br />
------=_Part_6401_1807263504.1501714598251--
------=_Part_6400_1396982999.1501714598251--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Aug 2017 02:37:58 +0300
Raw View
On 3 August 2017 at 01:56, Arthur O'Dwyer <arthur.j.odwyer@gmail.com> wrote:
> FYI, this exact puzzle (variadic "catch") was discussed in the
> #meta_programming Slack channel on June 30th; participants were Vittorio
> Romeo, Barry Revzin, Eric Niebler, Peter Dimov, and myself (belatedly). My
> solution is here. Its punch line is:
>
> try {
> throw Derived(); // this is just a placeholder for some code
> that might throw
> } catch (...) {
> variant_catch<const Derived&, const Base&>([](auto&& e) {
> printf("caught %s (%s)\n", typeid(e).name(),
> __PRETTY_FUNCTION__);
> });
> }
>
> but with the caveat that this signature (also provided at the Wandbox link
> above) will be more performant (not that we care about the performance of
> the exceptional path, of course):
>
> variant_catch<const Derived&, const Base&>([&]() {
> throw Derived(); // this is just a placeholder for some code that
> might throw
> }, [](auto&& e) {
> printf("caught %s (%s)\n", typeid(e).name(), __PRETTY_FUNCTION__);
> });
Note that both of our solutions suffer from the problem that the code
in the catch-clause
cannot break, continue, goto or return like plain code could. An
if-else chain of any_casts
from exception_ptr would be able to do that.
--
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/CAFk2RUZncz91iozp5d%3DWVhPCHwLa67dhmpwBRMEU5xioJvPuRA%40mail.gmail.com.
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Thu, 3 Aug 2017 16:17:43 -0700 (PDT)
Raw View
------=_Part_295_1335713273.1501802263600
Content-Type: multipart/alternative;
boundary="----=_Part_296_2103261817.1501802263600"
------=_Part_296_2103261817.1501802263600
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Wednesday, August 2, 2017 at 4:38:01 PM UTC-7, Ville Voutilainen wrote:
>
>
> Note that both of our solutions suffer from the problem that the code=20
> in the catch-clause=20
> cannot break, continue, goto or return like plain code could. An=20
> if-else chain of any_casts=20
> from exception_ptr would be able to do that.=20
>
Do you think LEWG would be amenable to a proposal to make std::any_cast an=
=20
all-purpose "type-un-erasing" mechanism in C++2a?
Right now we have a different type-un-erasure mechanism for each=20
type-erased type, and more proliferating with each revision of the Standard=
:
std::any a =3D xx;assert( std::any_cast<Type>(a) =3D=3D 42 );
std::function<long()> f =3D xx;assert( *f.target<Type>() =3D=3D xx );
std::shared_ptr<int> p(new int, xx);assert( *std::get_deleter<Type>(p) =3D=
=3D xx );
(from=20
https://stackoverflow.com/questions/44788017/retrieve-typeid-of-shared-ptr-=
deleter
)
(and from this thread, we can add std::exception_ptr to the list of=20
type-erased types)
I'm not sure "any_cast" would necessarily be the right spelling, but it is=
=20
pretty awkward IMHO that various library designers keep reinventing it over=
=20
and over with different spellings.
=E2=80=93Arthur
--=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/4c872807-7d50-4b58-bbb5-595a8bac1246%40isocpp.or=
g.
------=_Part_296_2103261817.1501802263600
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, August 2, 2017 at 4:38:01 PM UTC-7, Ville Vo=
utilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>Note that both of our solutions suffer from the problem that the code
<br>in the catch-clause
<br>cannot break, continue, goto or return like plain code could. An
<br>if-else chain of any_casts
<br>from exception_ptr would be able to do that.
<br></blockquote><div><br></div><div>Do you think LEWG would be amenable to=
a proposal to make std::any_cast an all-purpose "type-un-erasing"=
; mechanism in C++2a?</div><div>Right now we have a different type-un-erasu=
re mechanism for each type-erased type, and more proliferating with each re=
vision of the Standard:</div><div><br></div><div><pre class=3D"default pret=
typrint prettyprinted" style=3D"margin-bottom: 1em; padding: 5px; font-fami=
ly: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono=
', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', '=
;Courier New', monospace, sans-serif; line-height: inherit; vertical-al=
ign: baseline; width: auto; max-height: 600px; overflow: auto; background-c=
olor: rgb(239, 240, 241); color: rgb(57, 51, 24); word-wrap: normal;"><code=
style=3D"font-family: Consolas, Menlo, Monaco, 'Lucida Console', &=
#39;Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera S=
ans Mono', 'Courier New', monospace, sans-serif; font-style: in=
herit; font-variant-caps: inherit; line-height: inherit; vertical-align: ba=
seline; white-space: inherit;"><span class=3D"pln" style=3D"font-family: in=
herit; font-size: inherit; font-style: inherit; font-variant-caps: inherit;=
line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">s=
td</span><span class=3D"pun" style=3D"font-family: inherit; font-size: inhe=
rit; font-style: inherit; font-variant-caps: inherit; line-height: inherit;=
vertical-align: baseline; color: rgb(48, 51, 54);">::</span><span class=3D=
"pln" style=3D"font-family: inherit; font-size: inherit; font-style: inheri=
t; font-variant-caps: inherit; line-height: inherit; vertical-align: baseli=
ne; color: rgb(48, 51, 54);">any a </span><span class=3D"pun" style=3D"font=
-family: inherit; font-size: inherit; font-style: inherit; font-variant-cap=
s: inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, =
51, 54);">=3D</span><span class=3D"pln" style=3D"font-family: inherit; font=
-size: inherit; font-style: inherit; font-variant-caps: inherit; line-heigh=
t: inherit; vertical-align: baseline; color: rgb(48, 51, 54);"> xx</span><s=
pan class=3D"pun" style=3D"font-family: inherit; font-size: inherit; font-s=
tyle: inherit; font-variant-caps: inherit; line-height: inherit; vertical-a=
lign: baseline; color: rgb(48, 51, 54);">;</span><span class=3D"pln" style=
=3D"font-family: inherit; font-size: inherit; font-style: inherit; font-var=
iant-caps: inherit; line-height: inherit; vertical-align: baseline; color: =
rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"font-family: inherit; font-size: inheri=
t; font-style: inherit; font-variant-caps: inherit; line-height: inherit; v=
ertical-align: baseline; color: rgb(16, 16, 148);">assert</span><span class=
=3D"pun" style=3D"font-family: inherit; font-size: inherit; font-style: inh=
erit; font-variant-caps: inherit; line-height: inherit; vertical-align: bas=
eline; color: rgb(48, 51, 54);">(</span><span class=3D"pln" style=3D"font-f=
amily: inherit; font-size: inherit; font-style: inherit; font-variant-caps:=
inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51=
, 54);"> std</span><span class=3D"pun" style=3D"font-family: inherit; font-=
size: inherit; font-style: inherit; font-variant-caps: inherit; line-height=
: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">::</span><spa=
n class=3D"pln" style=3D"font-family: inherit; font-size: inherit; font-sty=
le: inherit; font-variant-caps: inherit; line-height: inherit; vertical-ali=
gn: baseline; color: rgb(48, 51, 54);">any_cast</span><span class=3D"pun" s=
tyle=3D"font-family: inherit; font-size: inherit; font-style: inherit; font=
-variant-caps: inherit; line-height: inherit; vertical-align: baseline; col=
or: rgb(48, 51, 54);"><</span><span class=3D"typ" style=3D"font-family: =
inherit; font-size: inherit; font-style: inherit; font-variant-caps: inheri=
t; line-height: inherit; vertical-align: baseline; color: rgb(43, 145, 175)=
;">Type</span><span class=3D"pun" style=3D"font-family: inherit; font-size:=
inherit; font-style: inherit; font-variant-caps: inherit; line-height: inh=
erit; vertical-align: baseline; color: rgb(48, 51, 54);">>(</span><span =
class=3D"pln" style=3D"font-family: inherit; font-size: inherit; font-style=
: inherit; font-variant-caps: inherit; line-height: inherit; vertical-align=
: baseline; color: rgb(48, 51, 54);">a</span><span class=3D"pun" style=3D"f=
ont-family: inherit; font-size: inherit; font-style: inherit; font-variant-=
caps: inherit; line-height: inherit; vertical-align: baseline; color: rgb(4=
8, 51, 54);">)</span><span class=3D"pln" style=3D"font-family: inherit; fon=
t-size: inherit; font-style: inherit; font-variant-caps: inherit; line-heig=
ht: inherit; vertical-align: baseline; color: rgb(48, 51, 54);"> </span><sp=
an class=3D"pun" style=3D"font-family: inherit; font-size: inherit; font-st=
yle: inherit; font-variant-caps: inherit; line-height: inherit; vertical-al=
ign: baseline; color: rgb(48, 51, 54);">=3D=3D</span><span class=3D"pln" st=
yle=3D"font-family: inherit; font-size: inherit; font-style: inherit; font-=
variant-caps: inherit; line-height: inherit; vertical-align: baseline; colo=
r: rgb(48, 51, 54);"> </span><span class=3D"lit" style=3D"font-family: inhe=
rit; font-size: inherit; font-style: inherit; font-variant-caps: inherit; l=
ine-height: inherit; vertical-align: baseline; color: rgb(125, 39, 39);">42=
</span><span class=3D"pln" style=3D"font-family: inherit; font-size: inheri=
t; font-style: inherit; font-variant-caps: inherit; line-height: inherit; v=
ertical-align: baseline; color: rgb(48, 51, 54);"> </span><span class=3D"pu=
n" style=3D"font-family: inherit; font-size: inherit; font-style: inherit; =
font-variant-caps: inherit; line-height: inherit; vertical-align: baseline;=
color: rgb(48, 51, 54);">);</span><span class=3D"pln" style=3D"font-family=
: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inhe=
rit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54)=
;">
</span><span class=3D"pln" style=3D"font-family: inherit; font-size: inheri=
t; font-style: inherit; font-variant-caps: inherit; line-height: inherit; v=
ertical-align: baseline; color: rgb(48, 51, 54);">std</span><span class=3D"=
pun" style=3D"font-family: inherit; font-size: inherit; font-style: inherit=
; font-variant-caps: inherit; line-height: inherit; vertical-align: baselin=
e; color: rgb(48, 51, 54);">::</span><span class=3D"kwd" style=3D"font-fami=
ly: inherit; font-size: inherit; font-style: inherit; font-variant-caps: in=
herit; line-height: inherit; vertical-align: baseline; color: rgb(16, 16, 1=
48);">function</span><span class=3D"pun" style=3D"font-family: inherit; fon=
t-size: inherit; font-style: inherit; font-variant-caps: inherit; line-heig=
ht: inherit; vertical-align: baseline; color: rgb(48, 51, 54);"><</span>=
<span class=3D"kwd" style=3D"font-family: inherit; font-size: inherit; font=
-style: inherit; font-variant-caps: inherit; line-height: inherit; vertical=
-align: baseline; color: rgb(16, 16, 148);">long</span><span class=3D"pun" =
style=3D"font-family: inherit; font-size: inherit; font-style: inherit; fon=
t-variant-caps: inherit; line-height: inherit; vertical-align: baseline; co=
lor: rgb(48, 51, 54);">()></span><span class=3D"pln" style=3D"font-famil=
y: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inh=
erit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54=
);"> f </span><span class=3D"pun" style=3D"font-family: inherit; font-size:=
inherit; font-style: inherit; font-variant-caps: inherit; line-height: inh=
erit; vertical-align: baseline; color: rgb(48, 51, 54);">=3D</span><span cl=
ass=3D"pln" style=3D"font-family: inherit; font-size: inherit; font-style: =
inherit; font-variant-caps: inherit; line-height: inherit; vertical-align: =
baseline; color: rgb(48, 51, 54);"> xx</span><span class=3D"pun" style=3D"f=
ont-family: inherit; font-size: inherit; font-style: inherit; font-variant-=
caps: inherit; line-height: inherit; vertical-align: baseline; color: rgb(4=
8, 51, 54);">;</span><span class=3D"pln" style=3D"font-family: inherit; fon=
t-size: inherit; font-style: inherit; font-variant-caps: inherit; line-heig=
ht: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"font-family: inherit; font-size: inheri=
t; font-style: inherit; font-variant-caps: inherit; line-height: inherit; v=
ertical-align: baseline; color: rgb(16, 16, 148);">assert</span><span class=
=3D"pun" style=3D"font-family: inherit; font-size: inherit; font-style: inh=
erit; font-variant-caps: inherit; line-height: inherit; vertical-align: bas=
eline; color: rgb(48, 51, 54);">(</span><span class=3D"pln" style=3D"font-f=
amily: inherit; font-size: inherit; font-style: inherit; font-variant-caps:=
inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51=
, 54);"> </span><span class=3D"pun" style=3D"font-family: inherit; font-siz=
e: inherit; font-style: inherit; font-variant-caps: inherit; line-height: i=
nherit; vertical-align: baseline; color: rgb(48, 51, 54);">*</span><span cl=
ass=3D"pln" style=3D"font-family: inherit; font-size: inherit; font-style: =
inherit; font-variant-caps: inherit; line-height: inherit; vertical-align: =
baseline; color: rgb(48, 51, 54);">f</span><span class=3D"pun" style=3D"fon=
t-family: inherit; font-size: inherit; font-style: inherit; font-variant-ca=
ps: inherit; line-height: inherit; vertical-align: baseline; color: rgb(48,=
51, 54);">.</span><span class=3D"pln" style=3D"font-family: inherit; font-=
size: inherit; font-style: inherit; font-variant-caps: inherit; line-height=
: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">target</span>=
<span class=3D"pun" style=3D"font-family: inherit; font-size: inherit; font=
-style: inherit; font-variant-caps: inherit; line-height: inherit; vertical=
-align: baseline; color: rgb(48, 51, 54);"><</span><span class=3D"typ" s=
tyle=3D"font-family: inherit; font-size: inherit; font-style: inherit; font=
-variant-caps: inherit; line-height: inherit; vertical-align: baseline; col=
or: rgb(43, 145, 175);">Type</span><span class=3D"pun" style=3D"font-family=
: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inhe=
rit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54)=
;">>()</span><span class=3D"pln" style=3D"font-family: inherit; font-siz=
e: inherit; font-style: inherit; font-variant-caps: inherit; line-height: i=
nherit; vertical-align: baseline; color: rgb(48, 51, 54);"> </span><span cl=
ass=3D"pun" style=3D"font-family: inherit; font-size: inherit; font-style: =
inherit; font-variant-caps: inherit; line-height: inherit; vertical-align: =
baseline; color: rgb(48, 51, 54);">=3D=3D</span><span class=3D"pln" style=
=3D"font-family: inherit; font-size: inherit; font-style: inherit; font-var=
iant-caps: inherit; line-height: inherit; vertical-align: baseline; color: =
rgb(48, 51, 54);"> xx </span><span class=3D"pun" style=3D"font-family: inhe=
rit; font-size: inherit; font-style: inherit; font-variant-caps: inherit; l=
ine-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">);<=
/span><span class=3D"pln" style=3D"font-family: inherit; font-size: inherit=
; font-style: inherit; font-variant-caps: inherit; line-height: inherit; ve=
rtical-align: baseline; color: rgb(48, 51, 54);">
</span><span class=3D"pln" style=3D"font-family: inherit; font-size: inheri=
t; font-style: inherit; font-variant-caps: inherit; line-height: inherit; v=
ertical-align: baseline; color: rgb(48, 51, 54);">std</span><span class=3D"=
pun" style=3D"font-family: inherit; font-size: inherit; font-style: inherit=
; font-variant-caps: inherit; line-height: inherit; vertical-align: baselin=
e; color: rgb(48, 51, 54);">::</span><span class=3D"pln" style=3D"font-fami=
ly: inherit; font-size: inherit; font-style: inherit; font-variant-caps: in=
herit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 5=
4);">shared_ptr</span><span class=3D"str" style=3D"font-family: inherit; fo=
nt-size: inherit; font-style: inherit; font-variant-caps: inherit; line-hei=
ght: inherit; vertical-align: baseline; color: rgb(125, 39, 39);"><int&g=
t;</span><span class=3D"pln" style=3D"font-family: inherit; font-size: inhe=
rit; font-style: inherit; font-variant-caps: inherit; line-height: inherit;=
vertical-align: baseline; color: rgb(48, 51, 54);"> p</span><span class=3D=
"pun" style=3D"font-family: inherit; font-size: inherit; font-style: inheri=
t; font-variant-caps: inherit; line-height: inherit; vertical-align: baseli=
ne; color: rgb(48, 51, 54);">(</span><span class=3D"kwd" style=3D"font-fami=
ly: inherit; font-size: inherit; font-style: inherit; font-variant-caps: in=
herit; line-height: inherit; vertical-align: baseline; color: rgb(16, 16, 1=
48);">new</span><span class=3D"pln" style=3D"font-family: inherit; font-siz=
e: inherit; font-style: inherit; font-variant-caps: inherit; line-height: i=
nherit; vertical-align: baseline; color: rgb(48, 51, 54);"> </span><span cl=
ass=3D"kwd" style=3D"font-family: inherit; font-size: inherit; font-style: =
inherit; font-variant-caps: inherit; line-height: inherit; vertical-align: =
baseline; color: rgb(16, 16, 148);">int</span><span class=3D"pun" style=3D"=
font-family: inherit; font-size: inherit; font-style: inherit; font-variant=
-caps: inherit; line-height: inherit; vertical-align: baseline; color: rgb(=
48, 51, 54);">,</span><span class=3D"pln" style=3D"font-family: inherit; fo=
nt-size: inherit; font-style: inherit; font-variant-caps: inherit; line-hei=
ght: inherit; vertical-align: baseline; color: rgb(48, 51, 54);"> xx</span>=
<span class=3D"pun" style=3D"font-family: inherit; font-size: inherit; font=
-style: inherit; font-variant-caps: inherit; line-height: inherit; vertical=
-align: baseline; color: rgb(48, 51, 54);">);</span><span class=3D"pln" sty=
le=3D"font-family: inherit; font-size: inherit; font-style: inherit; font-v=
ariant-caps: inherit; line-height: inherit; vertical-align: baseline; color=
: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"font-family: inherit; font-size: inheri=
t; font-style: inherit; font-variant-caps: inherit; line-height: inherit; v=
ertical-align: baseline; color: rgb(16, 16, 148);">assert</span><span class=
=3D"pun" style=3D"font-family: inherit; font-size: inherit; font-style: inh=
erit; font-variant-caps: inherit; line-height: inherit; vertical-align: bas=
eline; color: rgb(48, 51, 54);">(</span><span class=3D"pln" style=3D"font-f=
amily: inherit; font-size: inherit; font-style: inherit; font-variant-caps:=
inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51=
, 54);"> </span><span class=3D"pun" style=3D"font-family: inherit; font-siz=
e: inherit; font-style: inherit; font-variant-caps: inherit; line-height: i=
nherit; vertical-align: baseline; color: rgb(48, 51, 54);">*</span><span cl=
ass=3D"pln" style=3D"font-family: inherit; font-size: inherit; font-style: =
inherit; font-variant-caps: inherit; line-height: inherit; vertical-align: =
baseline; color: rgb(48, 51, 54);">std</span><span class=3D"pun" style=3D"f=
ont-family: inherit; font-size: inherit; font-style: inherit; font-variant-=
caps: inherit; line-height: inherit; vertical-align: baseline; color: rgb(4=
8, 51, 54);">::</span><span class=3D"pln" style=3D"font-family: inherit; fo=
nt-size: inherit; font-style: inherit; font-variant-caps: inherit; line-hei=
ght: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">get_delete=
r</span><span class=3D"pun" style=3D"font-family: inherit; font-size: inher=
it; font-style: inherit; font-variant-caps: inherit; line-height: inherit; =
vertical-align: baseline; color: rgb(48, 51, 54);"><</span><span class=
=3D"typ" style=3D"font-family: inherit; font-size: inherit; font-style: inh=
erit; font-variant-caps: inherit; line-height: inherit; vertical-align: bas=
eline; color: rgb(43, 145, 175);">Type</span><span class=3D"pun" style=3D"f=
ont-family: inherit; font-size: inherit; font-style: inherit; font-variant-=
caps: inherit; line-height: inherit; vertical-align: baseline; color: rgb(4=
8, 51, 54);">>(</span><span class=3D"pln" style=3D"font-family: inherit;=
font-size: inherit; font-style: inherit; font-variant-caps: inherit; line-=
height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">p</span=
><span class=3D"pun" style=3D"font-family: inherit; font-size: inherit; fon=
t-style: inherit; font-variant-caps: inherit; line-height: inherit; vertica=
l-align: baseline; color: rgb(48, 51, 54);">)</span><span class=3D"pln" sty=
le=3D"font-family: inherit; font-size: inherit; font-style: inherit; font-v=
ariant-caps: inherit; line-height: inherit; vertical-align: baseline; color=
: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"font-family: inher=
it; font-size: inherit; font-style: inherit; font-variant-caps: inherit; li=
ne-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">=3D=
=3D</span><span class=3D"pln" style=3D"font-family: inherit; font-size: inh=
erit; font-style: inherit; font-variant-caps: inherit; line-height: inherit=
; vertical-align: baseline; color: rgb(48, 51, 54);"> xx </span><span class=
=3D"pun" style=3D"font-family: inherit; font-size: inherit; font-style: inh=
erit; font-variant-caps: inherit; line-height: inherit; vertical-align: bas=
eline; color: rgb(48, 51, 54);">);</span></code></pre></div><div>(from=C2=
=A0<a href=3D"https://stackoverflow.com/questions/44788017/retrieve-typeid-=
of-shared-ptr-deleter">https://stackoverflow.com/questions/44788017/retriev=
e-typeid-of-shared-ptr-deleter</a>)<br></div><div>(and from this thread, we=
can add std::exception_ptr to the list of type-erased types)</div><div><br=
></div><div>I'm not sure "any_cast" would necessarily be the =
right spelling, but it is pretty awkward IMHO that various library designer=
s keep reinventing it over and over with different spellings.</div><div><br=
></div><div>=E2=80=93Arthur</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/4c872807-7d50-4b58-bbb5-595a8bac1246%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4c872807-7d50-4b58-bbb5-595a8bac1246=
%40isocpp.org</a>.<br />
------=_Part_296_2103261817.1501802263600--
------=_Part_295_1335713273.1501802263600--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 3 Aug 2017 16:49:45 -0700 (PDT)
Raw View
------=_Part_257_257773712.1501804185993
Content-Type: multipart/alternative;
boundary="----=_Part_258_1000085904.1501804185994"
------=_Part_258_1000085904.1501804185994
Content-Type: text/plain; charset="UTF-8"
On Thursday, August 3, 2017 at 7:17:43 PM UTC-4, Arthur O'Dwyer wrote:
>
> On Wednesday, August 2, 2017 at 4:38:01 PM UTC-7, Ville Voutilainen wrote:
>>
>>
>> Note that both of our solutions suffer from the problem that the code
>> in the catch-clause
>> cannot break, continue, goto or return like plain code could. An
>> if-else chain of any_casts
>> from exception_ptr would be able to do that.
>>
>
> Do you think LEWG would be amenable to a proposal to make std::any_cast an
> all-purpose "type-un-erasing" mechanism in C++2a?
> Right now we have a different type-un-erasure mechanism for each
> type-erased type, and more proliferating with each revision of the Standard:
>
> std::any a = xx;assert( std::any_cast<Type>(a) == 42 );
> std::function<long()> f = xx;assert( *f.target<Type>() == xx );
> std::shared_ptr<int> p(new int, xx);assert( *std::get_deleter<Type>(p) == xx );
>
> (from
> https://stackoverflow.com/questions/44788017/retrieve-typeid-of-shared-ptr-deleter
> )
> (and from this thread, we can add std::exception_ptr to the list of
> type-erased types)
>
> I'm not sure "any_cast" would necessarily be the right spelling, but it is
> pretty awkward IMHO that various library designers keep reinventing it over
> and over with different spellings.
>
>
Well, `any_cast` is most definitely not the right spelling. As shown with
`shared_ptr`, the deleter is something that is separate from the main
purpose of `shared_ptr`, so getting at it requires an interface that
shouldn't look like `func_name(ptr)`.
You might do it by having `get_deleter<>` return an implementation-defined
type that you can call `any_cast` or whatever on.
There's also the fact that it has to have different behavior. With
`any_cast`, you can move the object out of the `any` (the `any` is still
engaged with a moved-from value); with `function`, you don't have that
power.
But this is all getting pretty far afield from the main topic.
--
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/5aa1302e-36e6-499d-8936-ebd523f293f9%40isocpp.org.
------=_Part_258_1000085904.1501804185994
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Thursday, August 3, 2017 at 7:17:43 PM UTC-4, Arthur O&=
#39;Dwyer 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"lt=
r">On Wednesday, August 2, 2017 at 4:38:01 PM UTC-7, Ville Voutilainen wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bor=
der-left:1px #ccc solid;padding-left:1ex">
<br>Note that both of our solutions suffer from the problem that the code
<br>in the catch-clause
<br>cannot break, continue, goto or return like plain code could. An
<br>if-else chain of any_casts
<br>from exception_ptr would be able to do that.
<br></blockquote><div><br></div><div>Do you think LEWG would be amenable to=
a proposal to make std::any_cast an all-purpose "type-un-erasing"=
; mechanism in C++2a?</div><div>Right now we have a different type-un-erasu=
re mechanism for each type-erased type, and more proliferating with each re=
vision of the Standard:</div><div><br></div><div><pre style=3D"margin-botto=
m:1em;padding:5px;font-family:Consolas,Menlo,Monaco,'Lucida Console'=
;,'Liberation Mono','DejaVu Sans Mono','Bitstream Vera =
Sans Mono','Courier New',monospace,sans-serif;line-height:inher=
it;vertical-align:baseline;width:auto;max-height:600px;overflow:auto;backgr=
ound-color:rgb(239,240,241);color:rgb(57,51,24);word-wrap:normal"><code sty=
le=3D"font-family:Consolas,Menlo,Monaco,'Lucida Console','Liber=
ation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono=
9;,'Courier New',monospace,sans-serif;font-style:inherit;line-heigh=
t:inherit;vertical-align:baseline;white-space:inherit"><span style=3D"font-=
family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;ver=
tical-align:baseline;color:rgb(48,51,54)">std</span><span style=3D"font-fam=
ily:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertic=
al-align:baseline;color:rgb(48,51,54)">::</span><span style=3D"font-family:=
inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-a=
lign:baseline;color:rgb(48,51,54)">any a </span><span style=3D"font-family:=
inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-a=
lign:baseline;color:rgb(48,51,54)">=3D</span><span style=3D"font-family:inh=
erit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-alig=
n:baseline;color:rgb(48,51,54)"> xx</span><span style=3D"font-family:inheri=
t;font-size:inherit;font-style:inherit;line-height:inherit;vertical-align:b=
aseline;color:rgb(48,51,54)">;</span><span style=3D"font-family:inherit;fon=
t-size:inherit;font-style:inherit;line-height:inherit;vertical-align:baseli=
ne;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">asser=
t</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inh=
erit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</sp=
an><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;=
line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> std</span=
><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;li=
ne-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">::</span><sp=
an style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-h=
eight:inherit;vertical-align:baseline;color:rgb(48,51,54)">any_cast</span><=
span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line=
-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"><</span><sp=
an style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-h=
eight:inherit;vertical-align:baseline;color:rgb(43,145,175)">Type</span><sp=
an style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-h=
eight:inherit;vertical-align:baseline;color:rgb(48,51,54)">>(</span><spa=
n style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-he=
ight:inherit;vertical-align:baseline;color:rgb(48,51,54)">a</span><span sty=
le=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">)</span><span style=3D=
"font-family:inherit;font-size:inherit;font-style:inherit;line-height:inher=
it;vertical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font=
-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;ve=
rtical-align:baseline;color:rgb(48,51,54)">=3D=3D</span><span style=3D"font=
-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;ve=
rtical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-fami=
ly:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertica=
l-align:baseline;color:rgb(125,39,39)">42</span><span style=3D"font-family:=
inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-a=
lign:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-family:inher=
it;font-size:inherit;font-style:inherit;line-height:inherit;vertical-align:=
baseline;color:rgb(48,51,54)">);</span><span style=3D"font-family:inherit;f=
ont-size:inherit;font-style:inherit;line-height:inherit;vertical-align:base=
line;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">std</s=
pan><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit=
;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">::</span>=
<span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;lin=
e-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">function</sp=
an><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;=
line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"><</span=
><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;li=
ne-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">long</span>=
<span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;lin=
e-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">()></span>=
<span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;lin=
e-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> f </span><sp=
an style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-h=
eight:inherit;vertical-align:baseline;color:rgb(48,51,54)">=3D</span><span =
style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-heig=
ht:inherit;vertical-align:baseline;color:rgb(48,51,54)"> xx</span><span sty=
le=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><span style=3D=
"font-family:inherit;font-size:inherit;font-style:inherit;line-height:inher=
it;vertical-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">asser=
t</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inh=
erit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</sp=
an><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;=
line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><s=
pan style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-=
height:inherit;vertical-align:baseline;color:rgb(48,51,54)">*</span><span s=
tyle=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-heigh=
t:inherit;vertical-align:baseline;color:rgb(48,51,54)">f</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(48,51,54)">.</span><span style=3D"f=
ont-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit=
;vertical-align:baseline;color:rgb(48,51,54)">target</span><span style=3D"f=
ont-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit=
;vertical-align:baseline;color:rgb(48,51,54)"><</span><span style=3D"fon=
t-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;v=
ertical-align:baseline;color:rgb(43,145,175)">Type</span><span style=3D"fon=
t-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)">>()</span><span style=3D"fon=
t-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-fam=
ily:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertic=
al-align:baseline;color:rgb(48,51,54)">=3D=3D</span><span style=3D"font-fam=
ily:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertic=
al-align:baseline;color:rgb(48,51,54)"> xx </span><span style=3D"font-famil=
y:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical=
-align:baseline;color:rgb(48,51,54)">);</span><span style=3D"font-family:in=
herit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-ali=
gn:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">std</s=
pan><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit=
;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">::</span>=
<span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;lin=
e-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">shared_ptr</s=
pan><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit=
;line-height:inherit;vertical-align:baseline;color:rgb(125,39,39)"><int&=
gt;</span><span style=3D"font-family:inherit;font-size:inherit;font-style:i=
nherit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> p<=
/span><span style=3D"font-family:inherit;font-size:inherit;font-style:inher=
it;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span=
><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;li=
ne-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">new</span><=
span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line=
-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span =
style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-heig=
ht:inherit;vertical-align:baseline;color:rgb(16,16,148)">int</span><span st=
yle=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height=
:inherit;vertical-align:baseline;color:rgb(48,51,54)">,</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(48,51,54)"> xx</span><span style=3D=
"font-family:inherit;font-size:inherit;font-style:inherit;line-height:inher=
it;vertical-align:baseline;color:rgb(48,51,54)">);</span><span style=3D"fon=
t-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">asser=
t</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inh=
erit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</sp=
an><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;=
line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><s=
pan style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-=
height:inherit;vertical-align:baseline;color:rgb(48,51,54)">*</span><span s=
tyle=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-heigh=
t:inherit;vertical-align:baseline;color:rgb(48,51,54)">std</span><span styl=
e=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:i=
nherit;vertical-align:baseline;color:rgb(48,51,54)">::</span><span style=3D=
"font-family:inherit;font-size:inherit;font-style:inherit;line-height:inher=
it;vertical-align:baseline;color:rgb(48,51,54)">get_deleter</span><span sty=
le=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:=
inherit;vertical-align:baseline;color:rgb(48,51,54)"><</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(43,145,175)">Type</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(48,51,54)">>(</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(48,51,54)">p</span><span style=3D"f=
ont-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit=
;vertical-align:baseline;color:rgb(48,51,54)">)</span><span style=3D"font-f=
amily:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vert=
ical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-family=
:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-=
align:baseline;color:rgb(48,51,54)">=3D=3D</span><span style=3D"font-family=
:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-=
align:baseline;color:rgb(48,51,54)"> xx </span><span style=3D"font-family:i=
nherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)">);</span></code></pre></div><div>(from=C2=
=A0<a href=3D"https://stackoverflow.com/questions/44788017/retrieve-typeid-=
of-shared-ptr-deleter" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"th=
is.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.=
com%2Fquestions%2F44788017%2Fretrieve-typeid-of-shared-ptr-deleter\x26sa\x3=
dD\x26sntz\x3d1\x26usg\x3dAFQjCNEUHb8eX4u48og52SpAhJYZOgvDxA';return tr=
ue;" onclick=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%2=
F%2Fstackoverflow.com%2Fquestions%2F44788017%2Fretrieve-typeid-of-shared-pt=
r-deleter\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEUHb8eX4u48og52SpAhJYZOgv=
DxA';return true;">https://stackoverflow.<wbr>com/questions/44788017/<w=
br>retrieve-typeid-of-shared-ptr-<wbr>deleter</a>)<br></div><div>(and from =
this thread, we can add std::exception_ptr to the list of type-erased types=
)</div><div><br></div><div>I'm not sure "any_cast" would nece=
ssarily be the right spelling, but it is pretty awkward IMHO that various l=
ibrary designers keep reinventing it over and over with different spellings=
..</div><br></div></blockquote><div><br>Well, `any_cast` is most definitely =
not the right spelling. As shown with `shared_ptr`,=C2=A0 the deleter is so=
mething that is separate from the main purpose of `shared_ptr`, so getting =
at it requires an interface that shouldn't look like `func_name(ptr)`.<=
br><br>You might do it by having `get_deleter<>` return an implementa=
tion-defined type that you can call `any_cast` or whatever on.<br><br>There=
's also the fact that it has to have different behavior. With `any_cast=
`, you can move the object out of the `any` (the `any` is still engaged wit=
h a moved-from value); with `function`, you don't have that power.<br><=
br>But this is all getting pretty far afield from the main topic.<br></div>=
</div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/5aa1302e-36e6-499d-8936-ebd523f293f9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5aa1302e-36e6-499d-8936-ebd523f293f9=
%40isocpp.org</a>.<br />
------=_Part_258_1000085904.1501804185994--
------=_Part_257_257773712.1501804185993--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri, 4 Aug 2017 03:13:57 +0300
Raw View
On 4 August 2017 at 02:17, Arthur O'Dwyer <arthur.j.odwyer@gmail.com> wrote:
>> Note that both of our solutions suffer from the problem that the code
>> in the catch-clause
>> cannot break, continue, goto or return like plain code could. An
>> if-else chain of any_casts
>> from exception_ptr would be able to do that.
>
>
> Do you think LEWG would be amenable to a proposal to make std::any_cast an
> all-purpose "type-un-erasing" mechanism in C++2a?
Way to jump the gun. I doubt it, because it doesn't make sense to have
one name for
different things. However, unerasing the type of an any and an exception_ptr are
exactly the same.
> Right now we have a different type-un-erasure mechanism for each type-erased
> type, and more proliferating with each revision of the Standard:
>
> std::any a = xx;
> assert( std::any_cast<Type>(a) == 42 );
>
> std::function<long()> f = xx;
> assert( *f.target<Type>() == xx );
>
> std::shared_ptr<int> p(new int, xx);
> assert( *std::get_deleter<Type>(p) == xx );
>
> (from
> https://stackoverflow.com/questions/44788017/retrieve-typeid-of-shared-ptr-deleter)
> (and from this thread, we can add std::exception_ptr to the list of
> type-erased types)
>
> I'm not sure "any_cast" would necessarily be the right spelling, but it is
> pretty awkward IMHO that various library designers keep reinventing it over
> and over with different spellings.
Well, I suppose we could have an unerase(), if you can find enough
common functionality,
but if you want to make it fully generic, it needs to become a
customization point and oh
what fun that will be.
--
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/CAFk2RUa2teYd3DAg1VY3xF%3DvCNKUfna4emTSCYLuUa8dw_UmSg%40mail.gmail.com.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri, 4 Aug 2017 03:15:12 +0300
Raw View
On 4 August 2017 at 02:49, Nicol Bolas <jmckesson@gmail.com> wrote:
> Well, `any_cast` is most definitely not the right spelling. As shown with
Except for exception_ptr, it would be exactly the right spelling.
--
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/CAFk2RUZipWogjxCHDTHKSVyrYO6%2BKFgAw%3DH2W%3D%3Dkow%2BP8CiykQ%40mail.gmail.com.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 3 Aug 2017 18:25:02 -0700 (PDT)
Raw View
------=_Part_291_334164219.1501809902281
Content-Type: multipart/alternative;
boundary="----=_Part_292_1808809100.1501809902282"
------=_Part_292_1808809100.1501809902282
Content-Type: text/plain; charset="UTF-8"
On Thursday, August 3, 2017 at 8:14:00 PM UTC-4, Ville Voutilainen wrote:
>
> On 4 August 2017 at 02:17, Arthur O'Dwyer <arthur....@gmail.com
> <javascript:>> wrote:
> >> Note that both of our solutions suffer from the problem that the code
> >> in the catch-clause
> >> cannot break, continue, goto or return like plain code could. An
> >> if-else chain of any_casts
> >> from exception_ptr would be able to do that.
> >
> >
> > Do you think LEWG would be amenable to a proposal to make std::any_cast
> an
> > all-purpose "type-un-erasing" mechanism in C++2a?
>
> Way to jump the gun. I doubt it, because it doesn't make sense to have
> one name for
> different things. However, unerasing the type of an any and an
> exception_ptr are
> exactly the same.
>
Not really. The key difference being that `any_cast` typically returns a
copy of the object, while the exception pointer cast would return a pointer.
It should also be noted that the exception pointer cast needs to be able to
be cast to the actual exception type or any of its base classes. So if the
exception derives from `std::exception`, then doing
`exception_cast<std::exception>` should work. `any_cast` very much does not
have those semantics.
--
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/caf74994-b217-4108-80ce-664e64510e34%40isocpp.org.
------=_Part_292_1808809100.1501809902282
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, August 3, 2017 at 8:14:00 PM UTC-4, V=
ille Voutilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 4 Au=
gust 2017 at 02:17, Arthur O'Dwyer <<a href=3D"javascript:" target=
=3D"_blank" gdf-obfuscated-mailto=3D"oRFyWc05BgAJ" rel=3D"nofollow" onmouse=
down=3D"this.href=3D'javascript:';return true;" onclick=3D"this.hre=
f=3D'javascript:';return true;">arthur....@gmail.com</a>> wrote:
<br>>> Note that both of our solutions suffer from the problem that t=
he code
<br>>> in the catch-clause
<br>>> cannot break, continue, goto or return like plain code could. =
An
<br>>> if-else chain of any_casts
<br>>> from exception_ptr would be able to do that.
<br>>
<br>>
<br>> Do you think LEWG would be amenable to a proposal to make std::any=
_cast an
<br>> all-purpose "type-un-erasing" mechanism in C++2a?
<br>
<br>Way to jump the gun. I doubt it, because it doesn't make sense to h=
ave
<br>one name for
<br>different things. However, unerasing the type of an any and an exceptio=
n_ptr are
<br>exactly the same.<br></blockquote><div><br>Not really. The key differen=
ce being that `any_cast` typically returns a copy of the object, while the =
exception pointer cast would return a pointer.<br><br>It should also be not=
ed that the exception pointer cast needs to be able to be cast to the actua=
l exception type or any of its base classes. So if the exception derives fr=
om `std::exception`, then doing `exception_cast<std::exception>` shou=
ld work. `any_cast` very much does not have those semantics.</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/caf74994-b217-4108-80ce-664e64510e34%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/caf74994-b217-4108-80ce-664e64510e34=
%40isocpp.org</a>.<br />
------=_Part_292_1808809100.1501809902282--
------=_Part_291_334164219.1501809902281--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri, 4 Aug 2017 10:18:36 +0300
Raw View
On 4 August 2017 at 04:25, Nicol Bolas <jmckesson@gmail.com> wrote:
>> different things. However, unerasing the type of an any and an
>> exception_ptr are
>> exactly the same.
>
>
> Not really. The key difference being that `any_cast` typically returns a
> copy of the object, while the exception pointer cast would return a pointer.
>
> It should also be noted that the exception pointer cast needs to be able to
> be cast to the actual exception type or any of its base classes. So if the
> exception derives from `std::exception`, then doing
> `exception_cast<std::exception>` should work. `any_cast` very much does not
> have those semantics.
Ah, yes. Since we want to avoid the cast throwing (that's really the
whole point of allowing such access)
and we want to avoid slicing, it should perhaps *always* return a pointer. ;)
--
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/CAFk2RUYUnitYibRbvydnTY8RYPXOdUgsr89_WVN4SmLPixCcaA%40mail.gmail.com.
.
Author: Barry Revzin <barry.revzin@gmail.com>
Date: Fri, 4 Aug 2017 07:13:42 -0700 (PDT)
Raw View
------=_Part_750_1341051342.1501856022898
Content-Type: multipart/alternative;
boundary="----=_Part_751_997747254.1501856022899"
------=_Part_751_997747254.1501856022899
Content-Type: text/plain; charset="UTF-8"
>
> Do you think LEWG would be amenable to a proposal to make std::any_cast an
>> all-purpose "type-un-erasing" mechanism in C++2a?
>>
> Right now we have a different type-un-erasure mechanism for each
> type-erased type, and more proliferating with each revision of the Standard:
>
> std::any a = xx;assert( std::any_cast<Type>(a) == 42 );
> std::function<long()> f = xx;assert( *f.target<Type>() == xx );
> std::shared_ptr<int> p(new int, xx);assert( *std::get_deleter<Type>(p) == xx );
>
> (from
> https://stackoverflow.com/questions/44788017/retrieve-typeid-of-shared-ptr-deleter
> )
> (and from this thread, we can add std::exception_ptr to the list of
> type-erased types)
>
>
Depending on how broadly you want to define type erasure and the existence
of conditional casts to specific types, you could also throw in:
std::variant<A, B, C> var = a;
assert(std::get_if<A>(&var) == &a);
assert(std::get_if<0>(&var) == &a);
Base* p = some_derived;
assert(dynamic_cast<Derived*>(p) == some_derived);
Not really. The key difference being that `any_cast` typically returns a
> copy of the object, while the exception pointer cast would return a pointer.
I don't understand the use of "typically", the overloads that take an any* return
a pointer.
--
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/7fc5cc7e-b32f-4199-abc4-8eea86793226%40isocpp.org.
------=_Part_751_997747254.1501856022899
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex">Do you think LEWG would be amenable to a proposa=
l to make std::any_cast an all-purpose "type-un-erasing" mechanis=
m in C++2a?<br></blockquote><div>Right now we have a different type-un-eras=
ure mechanism for each type-erased type, and more proliferating with each r=
evision of the Standard:</div><div><br></div><div><pre style=3D"margin-bott=
om:1em;padding:5px;font-family:Consolas,Menlo,Monaco,'Lucida Console=
9;,'Liberation Mono','DejaVu Sans Mono','Bitstream Vera=
Sans Mono','Courier New',monospace,sans-serif;line-height:inhe=
rit;vertical-align:baseline;width:auto;max-height:600px;overflow:auto;backg=
round-color:rgb(239,240,241);color:rgb(57,51,24);word-wrap:normal"><code st=
yle=3D"font-family:Consolas,Menlo,Monaco,'Lucida Console','Libe=
ration Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono&#=
39;,'Courier New',monospace,sans-serif;font-style:inherit;line-heig=
ht:inherit;vertical-align:baseline;white-space:inherit"><span style=3D"font=
-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;ve=
rtical-align:baseline;color:rgb(48,51,54)">std</span><span style=3D"font-fa=
mily:inherit;font-size:inherit;font-style:inherit;line-height:inherit;verti=
cal-align:baseline;color:rgb(48,51,54)">::</span><span style=3D"font-family=
:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-=
align:baseline;color:rgb(48,51,54)">any a </span><span style=3D"font-family=
:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-=
align:baseline;color:rgb(48,51,54)">=3D</span><span style=3D"font-family:in=
herit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-ali=
gn:baseline;color:rgb(48,51,54)"> xx</span><span style=3D"font-family:inher=
it;font-size:inherit;font-style:inherit;line-height:inherit;vertical-align:=
baseline;color:rgb(48,51,54)">;</span><span style=3D"font-family:inherit;fo=
nt-size:inherit;font-style:inherit;line-height:inherit;vertical-align:basel=
ine;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">asser=
t</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inh=
erit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</sp=
an><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;=
line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> std</span=
><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;li=
ne-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">::</span><sp=
an style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-h=
eight:inherit;vertical-align:baseline;color:rgb(48,51,54)">any_cast</span><=
span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line=
-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"><</span><sp=
an style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-h=
eight:inherit;vertical-align:baseline;color:rgb(43,145,175)">Type</span><sp=
an style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-h=
eight:inherit;vertical-align:baseline;color:rgb(48,51,54)">>(</span><spa=
n style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-he=
ight:inherit;vertical-align:baseline;color:rgb(48,51,54)">a</span><span sty=
le=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">)</span><span style=3D=
"font-family:inherit;font-size:inherit;font-style:inherit;line-height:inher=
it;vertical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font=
-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;ve=
rtical-align:baseline;color:rgb(48,51,54)">=3D=3D</span><span style=3D"font=
-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;ve=
rtical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-fami=
ly:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertica=
l-align:baseline;color:rgb(125,39,39)">42</span><span style=3D"font-family:=
inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-a=
lign:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-family:inher=
it;font-size:inherit;font-style:inherit;line-height:inherit;vertical-align:=
baseline;color:rgb(48,51,54)">);</span><span style=3D"font-family:inherit;f=
ont-size:inherit;font-style:inherit;line-height:inherit;vertical-align:base=
line;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">std</s=
pan><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit=
;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">::</span>=
<span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;lin=
e-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">function</sp=
an><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;=
line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"><</span=
><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;li=
ne-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">long</span>=
<span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;lin=
e-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">()></span>=
<span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;lin=
e-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> f </span><sp=
an style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-h=
eight:inherit;vertical-align:baseline;color:rgb(48,51,54)">=3D</span><span =
style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-heig=
ht:inherit;vertical-align:baseline;color:rgb(48,51,54)"> xx</span><span sty=
le=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><span style=3D=
"font-family:inherit;font-size:inherit;font-style:inherit;line-height:inher=
it;vertical-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">asser=
t</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inh=
erit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</sp=
an><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;=
line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><s=
pan style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-=
height:inherit;vertical-align:baseline;color:rgb(48,51,54)">*</span><span s=
tyle=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-heigh=
t:inherit;vertical-align:baseline;color:rgb(48,51,54)">f</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(48,51,54)">.</span><span style=3D"f=
ont-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit=
;vertical-align:baseline;color:rgb(48,51,54)">target</span><span style=3D"f=
ont-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit=
;vertical-align:baseline;color:rgb(48,51,54)"><</span><span style=3D"fon=
t-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;v=
ertical-align:baseline;color:rgb(43,145,175)">Type</span><span style=3D"fon=
t-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)">>()</span><span style=3D"fon=
t-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-fam=
ily:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertic=
al-align:baseline;color:rgb(48,51,54)">=3D=3D</span><span style=3D"font-fam=
ily:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertic=
al-align:baseline;color:rgb(48,51,54)"> xx </span><span style=3D"font-famil=
y:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical=
-align:baseline;color:rgb(48,51,54)">);</span><span style=3D"font-family:in=
herit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-ali=
gn:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">std</s=
pan><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit=
;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">::</span>=
<span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;lin=
e-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">shared_ptr</s=
pan><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit=
;line-height:inherit;vertical-align:baseline;color:rgb(125,39,39)"><int&=
gt;</span><span style=3D"font-family:inherit;font-size:inherit;font-style:i=
nherit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> p<=
/span><span style=3D"font-family:inherit;font-size:inherit;font-style:inher=
it;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span=
><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;li=
ne-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">new</span><=
span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line=
-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span =
style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-heig=
ht:inherit;vertical-align:baseline;color:rgb(16,16,148)">int</span><span st=
yle=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height=
:inherit;vertical-align:baseline;color:rgb(48,51,54)">,</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(48,51,54)"> xx</span><span style=3D=
"font-family:inherit;font-size:inherit;font-style:inherit;line-height:inher=
it;vertical-align:baseline;color:rgb(48,51,54)">);</span><span style=3D"fon=
t-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inhe=
rit;line-height:inherit;vertical-align:baseline;color:rgb(16,16,148)">asser=
t</span><span style=3D"font-family:inherit;font-size:inherit;font-style:inh=
erit;line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</sp=
an><span style=3D"font-family:inherit;font-size:inherit;font-style:inherit;=
line-height:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><s=
pan style=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-=
height:inherit;vertical-align:baseline;color:rgb(48,51,54)">*</span><span s=
tyle=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-heigh=
t:inherit;vertical-align:baseline;color:rgb(48,51,54)">std</span><span styl=
e=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:i=
nherit;vertical-align:baseline;color:rgb(48,51,54)">::</span><span style=3D=
"font-family:inherit;font-size:inherit;font-style:inherit;line-height:inher=
it;vertical-align:baseline;color:rgb(48,51,54)">get_deleter</span><span sty=
le=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:=
inherit;vertical-align:baseline;color:rgb(48,51,54)"><</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(43,145,175)">Type</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(48,51,54)">>(</span><span style=
=3D"font-family:inherit;font-size:inherit;font-style:inherit;line-height:in=
herit;vertical-align:baseline;color:rgb(48,51,54)">p</span><span style=3D"f=
ont-family:inherit;font-size:inherit;font-style:inherit;line-height:inherit=
;vertical-align:baseline;color:rgb(48,51,54)">)</span><span style=3D"font-f=
amily:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vert=
ical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-family=
:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-=
align:baseline;color:rgb(48,51,54)">=3D=3D</span><span style=3D"font-family=
:inherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-=
align:baseline;color:rgb(48,51,54)"> xx </span><span style=3D"font-family:i=
nherit;font-size:inherit;font-style:inherit;line-height:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)">);</span></code></pre></div><div>(from=C2=
=A0<a href=3D"https://stackoverflow.com/questions/44788017/retrieve-typeid-=
of-shared-ptr-deleter" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"th=
is.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.=
com%2Fquestions%2F44788017%2Fretrieve-typeid-of-shared-ptr-deleter\x26sa\x3=
dD\x26sntz\x3d1\x26usg\x3dAFQjCNEUHb8eX4u48og52SpAhJYZOgvDxA';return tr=
ue;" onclick=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%2=
F%2Fstackoverflow.com%2Fquestions%2F44788017%2Fretrieve-typeid-of-shared-pt=
r-deleter\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEUHb8eX4u48og52SpAhJYZOgv=
DxA';return true;">https://stackoverflow.<wbr>com/questions/44788017/<w=
br>retrieve-typeid-of-shared-ptr-<wbr>deleter</a>)<br></div><div>(and from =
this thread, we can add std::exception_ptr to the list of type-erased types=
)</div><div><br></div></div></blockquote><div><br></div><div>Depending on h=
ow broadly you want to define type erasure and the existence of conditional=
casts to specific types, you could also throw in:</div><div><br></div><div=
><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); =
border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; w=
ord-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyp=
rint"><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">variant</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">A</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> B</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><font color=3D"#000000"><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> C</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">></span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">var</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">assert</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">get_if</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
A</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>(&=
;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">var</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">=3D=3D</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">a</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span></font><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">assert</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">get_if</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify"><</span><font color=
=3D"#000000"><span style=3D"color: #066;" class=3D"styled-by-prettify">0</s=
pan></font><span style=3D"color: #660;" class=3D"styled-by-prettify">>(&=
amp;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">var</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">a</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">);</span><font color=3D"#000000"><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #606;=
" class=3D"styled-by-prettify">Base</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> p </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> some_derived</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">assert</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">dynamic_cast</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">Derived</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">*>(</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">p</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D=3D</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> some_derived</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">);</span></font></div></code></div><br><br></div><blockquote=
class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-left: 1px=
solid rgb(204, 204, 204); padding-left: 1ex;">Not really. The key differen=
ce being that `any_cast` typically returns a copy of the object, while the =
exception pointer cast would return a pointer.</blockquote><div><br></div><=
div>I don't understand the use of =C2=A0"typically", the over=
loads that take an <font face=3D"courier new, monospace">any* </font>return=
a pointer.=C2=A0</div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/7fc5cc7e-b32f-4199-abc4-8eea86793226%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7fc5cc7e-b32f-4199-abc4-8eea86793226=
%40isocpp.org</a>.<br />
------=_Part_751_997747254.1501856022899--
------=_Part_750_1341051342.1501856022898--
.