Boost C++ Libraries: Ticket #2472: ptr_sequence_adapter<T>::sort fails to compile if T is an abstract base class https://svn.boost.org/trac10/ticket/2472 <p> When calling ptr_vector&lt;T&gt;::sort, where T is an abstract base class I get the following compilation error, on MSVC++2008: </p> <pre class="wiki">error C2027: use of undefined type 'boost::result_of&lt;F&gt;' 1&gt; with 1&gt; [ 1&gt; F=MyFunctorName(T,T) 1&gt; ] </pre><p> By making T a non-abstract base class (even though there should never be an element of type T in the container) the code compiles and runs as expected; therefore I believe I'm not missing any header files, nor is my compare functor faulted, so it might be a bug on the library. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2472 Trac 1.4.3 annonymous Thu, 06 Nov 2008 00:06:19 GMT <link>https://svn.boost.org/trac10/ticket/2472#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2472#comment:1</guid> <description> <p> Okay, so this isn't a problem with ptr_container per-se but rather a bug with MSVC, which might also manifest itself in other parts of the library. I'm posting a workaround that should fix the problem, but I still believe it should be taken into account and fixed in a future release. </p> <pre class="wiki">// --------------------------------------------------------------------------------------- // Fix for a bug in MSVC++ that made sort fail on ptr_containers which held pointers // to abstract types. Include and use sort_ptr_container(ptr_container [, function]). // Thanks goes to Dodheim who originally came up with this fix :-) // --------------------------------------------------------------------------------------- #include &lt;algorithm&gt; #include &lt;boost/type_traits/remove_pointer.hpp&gt; template&lt;typename Fun, typename Arg&gt; class indirect_compare { private: Fun fun; public: typedef bool result_type; indirect_compare() : fun(Fun()) {} indirect_compare(Fun f) : fun(f) {} result_type operator ()(const void* lhs, const void* rhs) const { return fun(*static_cast&lt;const Arg*&gt;(lhs), *static_cast&lt;const Arg*&gt;(rhs)); } }; template&lt;typename container_t&gt; void sort_ptr_container(container_t&amp; container) { typedef typename boost::remove_pointer&lt;typename container_t::value_type&gt;::type Arg; sort_ptr_container(container, std::less&lt;Arg&gt;()); } template&lt;typename container_t, typename Fun&gt; void sort_ptr_container(container_t&amp; container, Fun f) { typedef typename boost::remove_pointer&lt;typename container_t::value_type&gt;::type Arg; std::sort(container.begin().base(), container.end().base(), indirect_compare&lt;Fun, Arg&gt;(f)); } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 06 Nov 2008 02:50:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2472#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2472#comment:2</guid> <description> <p> Some more information. It seems that the problem resides with boost::result_of&lt;F&gt; being called as boost::result_of&lt;F(<a class="missing wiki">AbstractType</a>, <a class="missing wiki">AbstractType</a>)&gt;, even though F takes <a class="missing wiki">AbstractType</a>&amp; as argument. This doesn't compile in Microsoft Visual C++ 2008, though it has been said to work in some other compilers. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Thorsten Ottosen</dc:creator> <pubDate>Tue, 17 Feb 2009 22:53:17 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2472#comment:3 https://svn.boost.org/trac10/ticket/2472#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">fixed</span> </li> </ul> Ticket