Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[3.17.5.68] |
|
Сообщ.
#1
,
|
|
|
Есть нужда делать выборку по композитному ключу аки тут:
#include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/composite_key.hpp> struct phonebook_entry { std::string family_name; std::string given_name; std::string phone_number; phonebook_entry( std::string family_name, std::string given_name, std::string phone_number): family_name(family_name),given_name(given_name),phone_number(phone_number) {} }; // define a multi_index_container with a composite key on // (family_name,given_name) typedef multi_index_container< phonebook_entry, indexed_by< //non-unique as some subscribers might have more than one number ordered_non_unique< composite_key< phonebook_entry, member<phonebook_entry,std::string,&phonebook_entry::family_name>, member<phonebook_entry,std::string,&phonebook_entry::given_name> > >, ordered_unique< // unique as numbers belong to only one subscriber member<phonebook_entry,std::string,&phonebook_entry::phone_number> > > > phonebook; Но если скажем в phonebook_entry добавить еще несколько структур через агрегацию ( хочу делать выборку по их полям ) то подобная конструкция уже не компиляеться... struct new_index { int a; } struct phonebook_entry { std::string family_name; std::string given_name; std::string phone_number; new_index b; phonebook_entry( std::string family_name, std::string given_name, std::string phone_number): family_name(family_name),given_name(given_name),phone_number(phone_number) {} }; // define a multi_index_container with a composite key on // (family_name,given_name) typedef multi_index_container< phonebook_entry, indexed_by< //non-unique as some subscribers might have more than one number ordered_non_unique< composite_key< phonebook_entry, member<phonebook_entry,std::string,&phonebook_entry::family_name>, member<phonebook_entry,std::string,&phonebook_entry::given_name>, member<phonebook_entry,int,&phonebook_entry::a::b> > >, ordered_unique< // unique as numbers belong to only one subscriber member<phonebook_entry,std::string,&phonebook_entry::phone_number> > > > phonebook; |
Сообщ.
#2
,
|
|
|
Вообще говоря, тут дело не в мультииндексах. Указатели на агрегированные сущности требуют двойной косвенности. Посмотри:
struct A { int x; }; struct B { A y; }; //int A::* pmptr = &B::y.x; ошибка компиляции A B::* mptr = &B::y; int A::* pmptr= &A::x; B z; int main() { z.*mptr.*pmptr = 123; } |