[Multi_Index] Mixing composite keys with chained pointer value types

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Multi_Index] Mixing composite keys with chained pointer value types

Boost - Users mailing list
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).

The minimum source code I can construct to fail using GCC 5.4.0 or
Clang 3.9.1 with Boost 1.62 is attached in test.cpp, and the
compilation error from my version of clang is attached as
compilation-error.txt. I compile it with `clang++ --std=c++14
test.cpp`.

I'm not familiar with how the library works, but my surface-level
understanding is it seems that the chained_ptr is trying to act on the
value type, but the operand being passed is actually one of the
composite key expressions. I couldn't find much about how these two
mechanisms interact. In my case it's not strictly necessary that I
have this type-determining enum value, but it's cheaper than dynamic
casting, and it makes my life simpler, because there are also many
cases where we want to print the class name of the derived
instance. There are other approaches, but I don't want to use them if
I can get this working :)

-Nick Gordon

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users

test.cpp (827 bytes) Download Attachment
compilation-error.txt (28K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Multi_Index] Mixing composite keys with chained pointer value types

Boost - Users mailing list
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 mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users