For the below class, how do I represent the pointer to the member variable qux
of one of the instances of Bar
?
struct Foo {
struct Bar {
int qux;
} bar1, bar2;
};
This is needed when I use the boost::multi_index
container and need to use qux
as the key, which is needed in the key extractor
template<class Class,typename Type,Type Class::*PtrToMember>
struct boost::multi_index::member
I am assuming the intention is to create a boost multi_index container of
Foo
s and usequx
as the key. Thoughqux
isn't a member ofFoo
, you can achieve this by indexing on the memberFoo::bar1
and providing a custom comparison predicate for the ordered index. For example, if you are trying to create anordered_unique
key, you would write it like this:where
compare_foo_bar
is a friend ofFoo::Bar
and is defined as need: