Boost C++ Libraries: Ticket #2768: [any] Unique type_info https://svn.boost.org/trac10/ticket/2768 <p> Because typeid() does not return unique instance, we cannot use type_info instance pointer to compare types. And we cannot use type_info pointer with unorderd_*. </p> <p> # unorderd_map is useful to implement boost::any's multi method (visitor) to dispatch in constant-time. </p> <p> So I use static local variable in a function (like Singleton technique) to access type's type_info like this. <span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span><span class="underline"></span> </p> <pre class="wiki">namespace boost { class any { (snip) template&lt;typename ValueType&gt; static const std::type_info&amp; any::typeinfo() { static const std::type_info&amp; r(typeid(ValueType)); return r; } const std::type_info &amp; type() const { //return content ? content-&gt;type() : typeid(void); return content ? content-&gt;type() : typeinfo&lt;void&gt;(); } (snip) template&lt;typename ValueType&gt; class holder : public placeholder { (snip) virtual const std::type_info &amp; type() const { //return typeid(ValueType); return typeinfo&lt;ValueType&gt;(); } (snip) </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2768 Trac 1.4.3 nowake@… Tue, 17 Feb 2009 17:31:57 GMT attachment set https://svn.boost.org/trac10/ticket/2768 https://svn.boost.org/trac10/ticket/2768 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">any.hpp</span> </li> </ul> <p> boost::any that return unique type_info instance </p> Ticket anonymous Sun, 13 Sep 2009 19:33:52 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2768#comment:1 https://svn.boost.org/trac10/ticket/2768#comment:1 <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> Ticket nasonov Sun, 13 Sep 2009 22:22:52 GMT <link>https://svn.boost.org/trac10/ticket/2768#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2768#comment:2</guid> <description> <p> Anonymous who closed the bug was me. </p> </description> <category>Ticket</category> </item> </channel> </rss>