На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
Модераторы: Qraizer, Hsilgos
  
> boost multi_index
    Есть нужда делать выборку по композитному ключу аки тут:

    ExpandedWrap disabled
      #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 добавить еще несколько структур через агрегацию ( хочу делать выборку по их полям ) то подобная конструкция уже не компиляеться...

    ExpandedWrap disabled
      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;
    Сообщение отредактировано: Painkiller -
      Вообще говоря, тут дело не в мультииндексах. Указатели на агрегированные сущности требуют двойной косвенности. Посмотри:
      ExpandedWrap disabled
        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;
        }
      Возможно, тебе поможет member_offset, но я бы подумал о небольшом редизайне архитектуры.
      0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
      0 пользователей:


      Рейтинг@Mail.ru
      [ Script execution time: 0,0186 ]   [ 17 queries used ]   [ Generated: 19.04.24, 01:59 GMT ]