Boost logo

Boost Users :

Subject: [Boost-users] [Multi_Index] Mixing composite keys with chained pointer value types
From: Nick Gordon (nmgordon_at_[hidden])
Date: 2017-09-07 19:25:44


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 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