Boost logo

Boost Users :

Subject: Re: [Boost-users] [Multi_Index] Mixing composite keys with chained pointer value types
From: Joaquin M López Muñoz (joaquinlopezmunoz_at_[hidden])
Date: 2017-09-07 21:15:40


El 07/09/2017 a las 21:25, Nick Gordon via Boost-users escribió:
> I have a multi-index container that I'm using to fulfill two search
> cases. The objects are all derived from `Base`, which is a pure
> virtual class. To store the `Derived` objects I'm using unique_ptrs as
> the container value type. However, I need to store the objects
> uniquely on a composite of a member string, and an enum type used for
> runtime reflection without dynamic_cast-ing or typeid-ing. So, I want
> to use a composite key to be unique over both of these
> things. However, it doesn't compile (why else would I be posting) [...]

You're using

   boost::multi_index::composite_key<
     boost::multi_index::member<element, const int, &element::x>,
     boost::multi_index::member<element, const float, &element::y>
>

but composite_key requires that the first template argument be the type
on which the (following) key extractors are applied onto:

http://www.boost.org/libs/multi_index/doc/reference/key_extraction.html#composite_key

So, use

   boost::multi_index::composite_key<
     element,
     boost::multi_index::member<element, const int, &element::x>,
     boost::multi_index::member<element, const float, &element::y>
>

and you're done.

Joaquín M López Muñoz


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net