Topic: Add is_derived_from
Author: DeadMG <wolfeinstein@gmail.com>
Date: Fri, 22 Nov 2013 19:42:43 -0800 (PST)
Raw View
------=_Part_1_40424.1385178163379
Content-Type: text/plain; charset=ISO-8859-1
The Standard should provide a library function (or language routine but
library function would be better). This essentially serves as the base of
dynamic_cast. It takes the form
template<typename T> void* std::is_derived_from(T* p, std::type_info);
This doesn't really pose any more onerous requirements on implementations.
The return value is what you would get from dynamic_cast<Base>(p), where
Base is the type whose info is the second argument. The following program
shows how the existing RTTI requirements essentially mandate that
implementations provide something like this.
#include <iostream>
struct Base {
virtual void check() = 0;
template<typename T> T* IsDerivedFrom() {
try {
check();
} catch(T* p) {
return p;
} catch(...) {
return nullptr;
}
return nullptr;
}
};
template<typename T> struct Derived : public Base {
Derived(T obj) : t(obj) {}
T t;
void check() override final {
throw &t;
}
};
struct A { virtual ~A() {} virtual void print() = 0;};
struct B : public A { int x; B(int y) : x(y) {} void print() override final
{ std::cout << x; } };
int main() {
Base* b = new Derived<B>(B(5));
A* p = b->IsDerivedFrom<A>();
p->print();
}
As you can see, the program itself is quite contrived but also quite legal.
Itanium ABI implements something even more generic (a pair of type_info).
So I feel that this functionality could be quite safely provided to users
without creating a burden for implementations.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1_40424.1385178163379
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">The Standard should provide a library function (or languag=
e routine but library function would be better). This essentially serves as=
the base of dynamic_cast. It takes the form<div><br></div><div> &nbs=
p; template<typename T> void* std::is_derived_from(T* p, std::type_in=
fo);</div><div><br></div><div>This doesn't really pose any more onerous req=
uirements on implementations. The return value is what you would get from d=
ynamic_cast<Base>(p), where Base is the type whose info is the second=
argument. The following program shows how the existing RTTI requirements e=
ssentially mandate that implementations provide something like this.</div><=
div><br></div><div><div class=3D"prettyprint" style=3D"background-color: rg=
b(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-wo=
rd;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #800;" class=3D"styled-by-prettify">#include</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #080;" class=3D"styled-by-prettify"><iostream></span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">Base</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> </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">virtual</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> che=
ck</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">></span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> T</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: #606;" class=3D"styled-by-prettify">IsDerivedFrom</span><spa=
n 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> </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> che=
ck</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nbs=
p; </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">}</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: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">*</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"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"><br=
> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">return</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-b=
y-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"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">catch</span><span style=3D"color: #660;" class=3D"styled-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> &=
nbsp; </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </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><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">nullptr</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r></span><span style=3D"color: #008;" class=3D"styled-by-prettify">template=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">Derived</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">public</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #606;" class=3D"styled-by-prettify">Base</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> </span><span style=3D"color:=
#606;" class=3D"styled-by-prettify">Derived</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">T obj</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"> t</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">obj</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"st=
yled-by-prettify"><br> T t</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;" c=
lass=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> check</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">override</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">final</s=
pan><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> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">throw</sp=
an><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">t</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><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> A </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: #008;" class=3D"styled-by-prettify">virtual</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">~</span><span style=3D"colo=
r: #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"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{}</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">vi=
rtual</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">print</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-p=
rettify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> B </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">public</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: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
x</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 sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> y</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">y</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"> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">pri=
nt</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">override</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">final</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">cout </span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
;<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x</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">}</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"st=
yled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> main</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br> </sp=
an><span style=3D"color: #606;" class=3D"styled-by-prettify">Base</span><sp=
an 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"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">new</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pr=
ettify">Derived</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify">B=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">B</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">5</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">));</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br> A</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> p </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> b</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">-></span><span style=3D"color: #606;" class=3D"styled-by-prettify">I=
sDerivedFrom</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify">A</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">>();</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>  =
; p</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-></=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">print</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span></div></code></div><=
div><br></div></div><div>As you can see, the program itself is quite contri=
ved but also quite legal. Itanium ABI implements something even more generi=
c (a pair of type_info). So I feel that this functionality could be quite s=
afely provided to users without creating a burden for implementations.</div=
></div>
<p></p>
-- <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1_40424.1385178163379--
.
Author: David Krauss <potswa@gmail.com>
Date: Sat, 23 Nov 2013 12:05:59 +0800
Raw View
On 11/23/13 11:42 AM, DeadMG wrote:
> The Standard should provide a library function (or language routine but
> library function would be better). This essentially serves as the base of
> dynamic_cast. It takes the form
>
> template<typename T> void* std::is_derived_from(T* p, std::type_info);
I was wondering this the other day. It's an odd omission.
dynamic_cast will convert to a sibling base, not only "vertically," so
anything with "derived" would be a misnomer.
I'm not sure about the utility of the void *. If you're going to use it,
you might as well dynamic_cast. Is there a particular use case?
It might be better framed as a member function of type_info. What I
would expect would be
bool std::type_info::dynamic_convertible( std::type_info const & to )
const noexcept
A simpler name might be type_info::search().
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: DeadMG <wolfeinstein@gmail.com>
Date: Fri, 22 Nov 2013 20:20:50 -0800 (PST)
Raw View
------=_Part_218_3217575.1385180450303
Content-Type: text/plain; charset=ISO-8859-1
Oh, I hadn't considered that, but you're right. My proof-of-requirement
only proves that it's required that the implementation can search downwards
at runtime- not upwards or sideways, both of which dynamic_cast can do. But
you could also replace the first argument with a type_info if you wanted- I
managed to show that requiring one requires the other, or at the very
least, they can both be implemented on top of EH.
The void* is used because since you don't know Base at compile-time, you
can't return a strongly-typed Base* pointer. Essentially, the use of the
feature isn't just that X is derived from Y, but also allowing the caller
to perform that conversion at run-time without knowing X or Y statically
(although most uses would involve knowing at least one statically- for
example, boost::any_cast could use this). It's long been one of the most
unhappy parts of boost::any (and proposed std::any) interface that it's not
permitted to use any_cast<Base> and get back a Base& to an any holding a
Derived.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_218_3217575.1385180450303
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Oh, I hadn't considered that, but you're right. My proof-o=
f-requirement only proves that it's required that the implementation can se=
arch downwards at runtime- not upwards or sideways, both of which dynamic_c=
ast can do. But you could also replace the first argument with a type_info =
if you wanted- I managed to show that requiring one requires the other, or =
at the very least, they can both be implemented on top of EH.<div><br></div=
><div>The void* is used because since you don't know Base at compile-time, =
you can't return a strongly-typed Base* pointer. Essentially, the use of th=
e feature isn't just that X is derived from Y, but also allowing the caller=
to perform that conversion at run-time without knowing X or Y statically (=
although most uses would involve knowing at least one statically- for examp=
le, boost::any_cast could use this). It's long been one of the most unhappy=
parts of boost::any (and proposed std::any) interface that it's not permit=
ted to use any_cast<Base> and get back a Base& to an any holding =
a Derived.</div></div>
<p></p>
-- <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_218_3217575.1385180450303--
.
Author: phdofthehouse@gmail.com
Date: Fri, 22 Nov 2013 21:32:25 -0800 (PST)
Raw View
------=_Part_179_19883416.1385184745557
Content-Type: text/plain; charset=ISO-8859-1
Here's a quick implementation that uses the exception to do a "search". It
seems like it's able to do what it's supposed to do:
http://coliru.stacked-crooked.com/a/a1e8073f675cf8c1
I know that I'm using this trick ASAP. I can finally kiss those giant
"UObject" trees goodbye!
On Friday, November 22, 2013 10:42:43 PM UTC-5, DeadMG wrote:
>
> The Standard should provide a library function (or language routine but
> library function would be better). This essentially serves as the base of
> dynamic_cast. It takes the form
>
> template<typename T> void* std::is_derived_from(T* p, std::type_info);
>
> This doesn't really pose any more onerous requirements on implementations.
> The return value is what you would get from dynamic_cast<Base>(p), where
> Base is the type whose info is the second argument. The following program
> shows how the existing RTTI requirements essentially mandate that
> implementations provide something like this.
>
> #include <iostream>
>
> struct Base {
> virtual void check() = 0;
> template<typename T> T* IsDerivedFrom() {
> try {
> check();
> } catch(T* p) {
> return p;
> } catch(...) {
> return nullptr;
> }
> return nullptr;
> }
> };
>
> template<typename T> struct Derived : public Base {
> Derived(T obj) : t(obj) {}
> T t;
> void check() override final {
> throw &t;
> }
> };
>
> struct A { virtual ~A() {} virtual void print() = 0;};
> struct B : public A { int x; B(int y) : x(y) {} void print() override
> final { std::cout << x; } };
>
> int main() {
> Base* b = new Derived<B>(B(5));
> A* p = b->IsDerivedFrom<A>();
> p->print();
> }
>
> As you can see, the program itself is quite contrived but also quite
> legal. Itanium ABI implements something even more generic (a pair of
> type_info). So I feel that this functionality could be quite safely
> provided to users without creating a burden for implementations.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_179_19883416.1385184745557
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Here's a quick implementation that uses the exception to d=
o a "search". It seems like it's able to do what it's supposed to do:<br><b=
r>http://coliru.stacked-crooked.com/a/a1e8073f675cf8c1<br><br>I know that I=
'm using this trick ASAP. I can finally kiss those giant "UObject" trees go=
odbye!<br><br>On Friday, November 22, 2013 10:42:43 PM UTC-5, DeadMG wrote:=
<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">The Standard =
should provide a library function (or language routine but library function=
would be better). This essentially serves as the base of dynamic_cast. It =
takes the form<div><br></div><div> template<typename T> =
void* std::is_derived_from(T* p, std::type_info);</div><div><br></div><div>=
This doesn't really pose any more onerous requirements on implementations. =
The return value is what you would get from dynamic_cast<Base>(p), wh=
ere Base is the type whose info is the second argument. The following progr=
am shows how the existing RTTI requirements essentially mandate that implem=
entations provide something like this.</div><div><br></div><div><div style=
=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);wor=
d-wrap:break-word"><code><div><span style=3D"color:#800">#include</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#080"><iostream>=
</span><span style=3D"color:#000"><br><br></span><span style=3D"color:#008"=
>struct</span><span style=3D"color:#000"> </span><span style=3D"color:#606"=
>Base</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br> </span><span style=3D"c=
olor:#008">virtual</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">void</span><span style=3D"color:#000"> check</span><span style=
=3D"color:#660">()</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#066">0</span><span style=3D"color:#660">;</span><span style=3D"color:#0=
00"><br> </span><span style=3D"color:#008">template</span><spa=
n style=3D"color:#660"><</span><span style=3D"color:#008">typename</span=
><span style=3D"color:#000"> T</span><span style=3D"color:#660">></span>=
<span style=3D"color:#000"> T</span><span style=3D"color:#660">*</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">IsDerivedFrom</sp=
an><span style=3D"color:#660">()</span><span style=3D"color:#000"> </span><=
span style=3D"color:#660">{</span><span style=3D"color:#000"><br> &nb=
sp; </span><span style=3D"color:#008">try</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"><br> check</span><span =
style=3D"color:#660">();</span><span style=3D"color:#000"><br> =
</span><span style=3D"color:#660">}</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">catch</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#000">T</span><span style=3D"color:#66=
0">*</span><span style=3D"color:#000"> p</span><span style=3D"color:#660">)=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</spa=
n><span style=3D"color:#000"><br> =
</span><span style=3D"color:#008">return</span><span style=3D"color:#000"> =
p</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&=
nbsp; </span><span style=3D"color:#660">}</span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">catch</span><span s=
tyle=3D"color:#660">(...)</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">{</span><span style=3D"color:#000"><br> &nb=
sp; </span><span style=3D"color:#008">return</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">nullptr</span><s=
pan style=3D"color:#660">;</span><span style=3D"color:#000"><br> &nbs=
p; </span><span style=3D"color:#660">}</span><span style=3D"c=
olor:#000"><br> </span><span style=3D"color:#008=
">return</span><span style=3D"color:#000"> </span><span style=3D"color:#008=
">nullptr</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></span><span style=3D"color:#660">};</span><span style=
=3D"color:#000"><br><br></span><span style=3D"color:#008">template</span><s=
pan style=3D"color:#660"><</span><span style=3D"color:#008">typename</sp=
an><span style=3D"color:#000"> T</span><span style=3D"color:#660">></spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">struct</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#606">Derived</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">:</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">public</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#606">Base</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span sty=
le=3D"color:#000"><br> </span><span style=3D"color:#606">Deriv=
ed</span><span style=3D"color:#660">(</span><span style=3D"color:#000">T ob=
j</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">:</span><span style=3D"color:#000"> t</span><=
span style=3D"color:#660">(</span><span style=3D"color:#000">obj</span><spa=
n style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">{}</span><span style=3D"color:#000"><br> T t=
</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&n=
bsp; </span><span style=3D"color:#008">void</span><span style=3D"col=
or:#000"> check</span><span style=3D"color:#660">()</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">override</span><span style=3D"=
color:#000"> </span><span style=3D"color:#008">final</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"><br> </span><span style=3D"color:#008">thr=
ow</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&=
;</span><span style=3D"color:#000">t</span><span style=3D"color:#660">;</sp=
an><span style=3D"color:#000"><br> </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></span><span style=3D"colo=
r:#008">struct</span><span style=3D"color:#000"> A </span><span style=3D"co=
lor:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#=
008">virtual</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660">~</span><span style=3D"color:#000">A</span><span style=3D"color:#660"=
>()</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{}<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">virtual=
</span><span style=3D"color:#000"> </span><span style=3D"color:#008">void</=
span><span style=3D"color:#000"> </span><span style=3D"color:#008">print</s=
pan><span style=3D"color:#660">()</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#066">0</span><span style=3D"color:#660">;};</span><span =
style=3D"color:#000"><br></span><span style=3D"color:#008">struct</span><sp=
an style=3D"color:#000"> B </span><span style=3D"color:#660">:</span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">public</span><span =
style=3D"color:#000"> A </span><span style=3D"color:#660">{</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#008">int</span><span style=
=3D"color:#000"> x</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"> B</span><span style=3D"color:#660">(</span><span style=3D"colo=
r:#008">int</span><span style=3D"color:#000"> y</span><span style=3D"color:=
#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>:</span><span style=3D"color:#000"> x</span><span style=3D"color:#660">(</=
span><span style=3D"color:#000">y</span><span style=3D"color:#660">)</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">{}</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#008">void</span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">print</span><span s=
tyle=3D"color:#660">()</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">override</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#008">final</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#660">{</span><span style=3D"color:#000"> std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">cout </span><span style=
=3D"color:#660"><<</span><span style=3D"color:#000"> x</span><span st=
yle=3D"color:#660">;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">}</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">};</span><span style=3D"color:#000"><br><br></span><span style=
=3D"color:#008">int</span><span style=3D"color:#000"> main</span><span styl=
e=3D"color:#660">()</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">{</span><span style=3D"color:#000"><br> </span><s=
pan style=3D"color:#606">Base</span><span style=3D"color:#660">*</span><spa=
n style=3D"color:#000"> b </span><span style=3D"color:#660">=3D</span><span=
style=3D"color:#000"> </span><span style=3D"color:#008">new</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#606">Derived</span><span s=
tyle=3D"color:#660"><</span><span style=3D"color:#000">B</span><span sty=
le=3D"color:#660">>(</span><span style=3D"color:#000">B</span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#066">5</span><span style=3D"=
color:#660">));</span><span style=3D"color:#000"><br> A</span>=
<span style=3D"color:#660">*</span><span style=3D"color:#000"> p </span><sp=
an style=3D"color:#660">=3D</span><span style=3D"color:#000"> b</span><span=
style=3D"color:#660">-></span><span style=3D"color:#606">IsDerivedFrom<=
/span><span style=3D"color:#660"><</span><span style=3D"color:#000">A</s=
pan><span style=3D"color:#660">>();</span><span style=3D"color:#000"><br=
> p</span><span style=3D"color:#660">-></span><span style=
=3D"color:#008">print</span><span style=3D"color:#660">();</span><span styl=
e=3D"color:#000"><br></span><span style=3D"color:#660">}</span></div></code=
></div><div><br></div></div><div>As you can see, the program itself is quit=
e contrived but also quite legal. Itanium ABI implements something even mor=
e generic (a pair of type_info). So I feel that this functionality could be=
quite safely provided to users without creating a burden for implementatio=
ns.</div></div></blockquote></div>
<p></p>
-- <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_179_19883416.1385184745557--
.
Author: phdofthehouse@gmail.com
Date: Fri, 22 Nov 2013 22:02:42 -0800 (PST)
Raw View
------=_Part_197_23292772.1385186562812
Content-Type: text/plain; charset=ISO-8859-1
Now with a `catch` type too, to make it so a user can check two typeid's
for inheritance against each other:
http://coliru.stacked-crooked.com/a/8b1d23b414f97da0
On Friday, November 22, 2013 10:42:43 PM UTC-5, DeadMG wrote:
>
> The Standard should provide a library function (or language routine but
> library function would be better). This essentially serves as the base of
> dynamic_cast. It takes the form
>
> template<typename T> void* std::is_derived_from(T* p, std::type_info);
>
> This doesn't really pose any more onerous requirements on implementations.
> The return value is what you would get from dynamic_cast<Base>(p), where
> Base is the type whose info is the second argument. The following program
> shows how the existing RTTI requirements essentially mandate that
> implementations provide something like this.
>
> #include <iostream>
>
> struct Base {
> virtual void check() = 0;
> template<typename T> T* IsDerivedFrom() {
> try {
> check();
> } catch(T* p) {
> return p;
> } catch(...) {
> return nullptr;
> }
> return nullptr;
> }
> };
>
> template<typename T> struct Derived : public Base {
> Derived(T obj) : t(obj) {}
> T t;
> void check() override final {
> throw &t;
> }
> };
>
> struct A { virtual ~A() {} virtual void print() = 0;};
> struct B : public A { int x; B(int y) : x(y) {} void print() override
> final { std::cout << x; } };
>
> int main() {
> Base* b = new Derived<B>(B(5));
> A* p = b->IsDerivedFrom<A>();
> p->print();
> }
>
> As you can see, the program itself is quite contrived but also quite
> legal. Itanium ABI implements something even more generic (a pair of
> type_info). So I feel that this functionality could be quite safely
> provided to users without creating a burden for implementations.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_197_23292772.1385186562812
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Now with a `catch` type too, to make it so a user can chec=
k two typeid's for inheritance against each other:<br>http://coliru.stacked=
-crooked.com/a/8b1d23b414f97da0<br><br>On Friday, November 22, 2013 10:42:4=
3 PM UTC-5, DeadMG 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"ltr">The Standard should provide a library function (or language rou=
tine but library function would be better). This essentially serves as the =
base of dynamic_cast. It takes the form<div><br></div><div> te=
mplate<typename T> void* std::is_derived_from(T* p, std::type_info);<=
/div><div><br></div><div>This doesn't really pose any more onerous requirem=
ents on implementations. The return value is what you would get from dynami=
c_cast<Base>(p), where Base is the type whose info is the second argu=
ment. The following program shows how the existing RTTI requirements essent=
ially mandate that implementations provide something like this.</div><div><=
br></div><div><div style=3D"background-color:rgb(250,250,250);border:1px so=
lid rgb(187,187,187);word-wrap:break-word"><code><div><span style=3D"color:=
#800">#include</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#080"><iostream></span><span style=3D"color:#000"><br><br></span><s=
pan style=3D"color:#008">struct</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#606">Base</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">{</span><span style=3D"color:#000"><br> =
</span><span style=3D"color:#008">virtual</span><span style=3D"color:#000"=
> </span><span style=3D"color:#008">void</span><span style=3D"color:#000"> =
check</span><span style=3D"color:#660">()</span><span style=3D"color:#000">=
</span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">0</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"><br> </span><span style=3D"color:#0=
08">template</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#008">typename</span><span style=3D"color:#000"> T</span><span style=3D"=
color:#660">></span><span style=3D"color:#000"> T</span><span style=3D"c=
olor:#660">*</span><span style=3D"color:#000"> </span><span style=3D"color:=
#606">IsDerivedFrom</span><span style=3D"color:#660">()</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"><br> </span><span style=3D"color:#008=
">try</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br> &n=
bsp; check</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</s=
pan><span style=3D"color:#660">(</span><span style=3D"color:#000">T</span><=
span style=3D"color:#660">*</span><span style=3D"color:#000"> p</span><span=
style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#660">{</span><span style=3D"color:#000"><br>  =
; </span><span style=3D"color:#008">return</span><span=
style=3D"color:#000"> p</span><span style=3D"color:#660">;</span><span sty=
le=3D"color:#000"><br> </span><span style=3D"col=
or:#660">}</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
08">catch</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> </span><span style=3D"color=
:#008">return</span><span style=3D"color:#000"> </span><span style=3D"color=
:#008">nullptr</span><span style=3D"color:#660">;</span><span style=3D"colo=
r:#000"><br> </span><span style=3D"color:#660">}=
</span><span style=3D"color:#000"><br> </span><s=
pan style=3D"color:#008">return</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">nullptr</span><span style=3D"color:#660">;</span><=
span style=3D"color:#000"><br> </span><span style=3D"color:#66=
0">}</span><span style=3D"color:#000"><br></span><span style=3D"color:#660"=
>};</span><span style=3D"color:#000"><br><br></span><span style=3D"color:#0=
08">template</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#008">typename</span><span style=3D"color:#000"> T</span><span style=3D"=
color:#660">></span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#008">struct</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#606">Derived</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">public</span><span style=3D"color:#000"> </span><span style=3D"color:=
#606">Base</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"><br> </span><span style=
=3D"color:#606">Derived</span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#000">T obj</span><span style=3D"color:#660">)</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">:</span><span style=3D"c=
olor:#000"> t</span><span style=3D"color:#660">(</span><span style=3D"color=
:#000">obj</span><span style=3D"color:#660">)</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">{}</span><span style=3D"color:#000">=
<br> T t</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br> </span><span style=3D"color:#008">void</s=
pan><span style=3D"color:#000"> check</span><span style=3D"color:#660">()</=
span><span style=3D"color:#000"> </span><span style=3D"color:#008">override=
</span><span style=3D"color:#000"> </span><span style=3D"color:#008">final<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span=
><span style=3D"color:#000"><br> </span><span st=
yle=3D"color:#008">throw</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">&</span><span style=3D"color:#000">t</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br> </spa=
n><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></sp=
an><span style=3D"color:#008">struct</span><span style=3D"color:#000"> A </=
span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#008">virtual</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">~</span><span style=3D"color:#000">A</span><spa=
n style=3D"color:#660">()</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">{}</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">virtual</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#008">void</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">print</span><span style=3D"color:#660">()</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><span style=3D=
"color:#000"> </span><span style=3D"color:#066">0</span><span style=3D"colo=
r:#660">;};</span><span style=3D"color:#000"><br></span><span style=3D"colo=
r:#008">struct</span><span style=3D"color:#000"> B </span><span style=3D"co=
lor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#=
008">public</span><span style=3D"color:#000"> A </span><span style=3D"color=
:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#008=
">int</span><span style=3D"color:#000"> x</span><span style=3D"color:#660">=
;</span><span style=3D"color:#000"> B</span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#008">int</span><span style=3D"color:#000"> y</spa=
n><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">:</span><span style=3D"color:#000"> x</span><span s=
tyle=3D"color:#660">(</span><span style=3D"color:#000">y</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">{}</span><span style=3D"color:#000"> </span><span style=3D"color=
:#008">void</span><span style=3D"color:#000"> </span><span style=3D"color:#=
008">print</span><span style=3D"color:#660">()</span><span style=3D"color:#=
000"> </span><span style=3D"color:#008">override</span><span style=3D"color=
:#000"> </span><span style=3D"color:#008">final</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"=
> std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">=
cout </span><span style=3D"color:#660"><<</span><span style=3D"color:=
#000"> x</span><span style=3D"color:#660">;</span><span style=3D"color:#000=
"> </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><br=
></span><span style=3D"color:#008">int</span><span style=3D"color:#000"> ma=
in</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>&nbs=
p; </span><span style=3D"color:#606">Base</span><span style=3D"color=
:#660">*</span><span style=3D"color:#000"> b </span><span style=3D"color:#6=
60">=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#008"=
>new</span><span style=3D"color:#000"> </span><span style=3D"color:#606">De=
rived</span><span style=3D"color:#660"><</span><span style=3D"color:#000=
">B</span><span style=3D"color:#660">>(</span><span style=3D"color:#000"=
>B</span><span style=3D"color:#660">(</span><span style=3D"color:#066">5</s=
pan><span style=3D"color:#660">));</span><span style=3D"color:#000"><br>&nb=
sp; A</span><span style=3D"color:#660">*</span><span style=3D"color:=
#000"> p </span><span style=3D"color:#660">=3D</span><span style=3D"color:#=
000"> b</span><span style=3D"color:#660">-></span><span style=3D"color:#=
606">IsDerivedFrom</span><span style=3D"color:#660"><</span><span style=
=3D"color:#000">A</span><span style=3D"color:#660">>();</span><span styl=
e=3D"color:#000"><br> p</span><span style=3D"color:#660">->=
</span><span style=3D"color:#008">print</span><span style=3D"color:#660">()=
;</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">}<=
/span></div></code></div><div><br></div></div><div>As you can see, the prog=
ram itself is quite contrived but also quite legal. Itanium ABI implements =
something even more generic (a pair of type_info). So I feel that this func=
tionality could be quite safely provided to users without creating a burden=
for implementations.</div></div></blockquote></div>
<p></p>
-- <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_197_23292772.1385186562812--
.