Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2472: ptr_sequence_adapter<T>::sort fails to compile if T is an abstract base class
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-11-06 00:06:20
#2472: ptr_sequence_adapter<T>::sort fails to compile if T is an abstract base
class
---------------------------+------------------------------------------------
Reporter: anonymous | Owner: nesotto
Type: Bugs | Status: new
Milestone: Boost 1.38.0 | Component: ptr_container
Version: Boost 1.36.0 | Severity: Problem
Resolution: | Keywords:
---------------------------+------------------------------------------------
Comment(by annonymous):
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.
{{{
//
---------------------------------------------------------------------------------------
// 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 <algorithm>
#include <boost/type_traits/remove_pointer.hpp>
template<typename Fun, typename Arg>
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<const Arg*>(lhs),
*static_cast<const Arg*>(rhs));
}
};
template<typename container_t>
void sort_ptr_container(container_t& container)
{
typedef typename boost::remove_pointer<typename
container_t::value_type>::type Arg;
sort_ptr_container(container, std::less<Arg>());
}
template<typename container_t, typename Fun>
void sort_ptr_container(container_t& container, Fun f)
{
typedef typename boost::remove_pointer<typename
container_t::value_type>::type Arg;
std::sort(container.begin().base(), container.end().base(),
indirect_compare<Fun, Arg>(f));
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/2472#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC