I appreciate the help. This worked perfectly.
Daniel Dilts <diltsman <at> gmail.com> writes:[...]
> I'm am using boost::multi_index to hold a set of polymorphic entities.
> Due to efficiency concerns, I have to be able sort the container based
> on actual type. I was planning on sorting based on the return result of
> typeid. When I try this I get errors in <functional>. I am using
> VC++ 2005 Standard Edition SP1. What am I doing wrong, or, what is a
> better way of accomplishing what I am trying to do?
>
> struct extractTypeHere is the first problem: you've got to define
> {
> typedef const type_info& result_type;
typedef type_info result_type
and let operator() return value be const result_type& (instead
of the current return_type).
Past the first hurdle you'll find that type_info is not comparable
with <, so you'll also need to provide a custom comparer for this type
based on type_info::before. The following summarizes all the changes
needed (note: do not forget to include <typeinfo>; also, you're using
type_info instead of std::type_info, which seems to work in VS but is not
standard as far as I know):
typedef std::type_info result_type;
namespace Entities
{
struct type{};
struct extractType
{
const result_type& operator()(const Entity * r)const
{
return typeid(*r);
}
};
struct lessType
{
bool operator()(const std::type_info& x, const std::type_info& y)const
{
return x.before(y);
}boost::multi_index::tag<type>, extractType, lessType
};
typedef boost::multi_index::multi_index_container<
Entity *,
boost::multi_index::indexed_by<
boost::multi_index::ordered_non_unique<
>
>
> EntityContainer;
};
Hope this helps. Thank you for using Boost.MultiIndex.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users