Boost C++ Libraries: Ticket #5768: any_cast https://svn.boost.org/trac10/ticket/5768 <p> assume we have a class Base, and other class Derived that inherits Base. </p> <p> I can write </p> <pre class="wiki">boost::any a = new Derived; </pre><p> so, the following code </p> <pre class="wiki">Derived* d = any_cast&lt;Derived*&gt;(a); </pre><p> will work good, but!! </p> <pre class="wiki">Base* b = any_cast&lt;Base*&gt;(a); </pre><p> will fail. </p> <p> i.e boost::any_cast could not work with inheritance and polymorphism. </p> <p> You may wonder why this is needed? but I did faced this case. </p> <p> I solved this problem in <strong>boost::any</strong> on my machine, and I thought to share this with others, so if this sounds useful to you, please tell me how can I add my code to boost </p> <p> many thanks. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5768 Trac 1.4.3 Antony Polukhin Wed, 27 Nov 2013 08:14:42 GMT <link>https://svn.boost.org/trac10/ticket/5768#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5768#comment:1</guid> <description> <p> This is discussed at the <a class="ext-link" href="http://boost.2283326.n4.nabble.com/More-flexible-any-cast-for-boost-any-td4655429.html"><span class="icon">​</span>following thread</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Wed, 05 Feb 2014 12:00:24 GMT</pubDate> <title>owner changed https://svn.boost.org/trac10/ticket/5768#comment:2 https://svn.boost.org/trac10/ticket/5768#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">nasonov</span> to <span class="trac-author">Antony Polukhin</span> </li> </ul> Ticket Antony Polukhin Wed, 18 Nov 2020 19:24:54 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5768#comment:3 https://svn.boost.org/trac10/ticket/5768#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> The proposed implementation throws a held type and tries to catch it by base type. This is a quite curious technique! </p> <p> Unfortunately it's not usable for production due to the exceptions being too heavy to throw and catch. </p> Ticket