Boost::multi_index_container 具有不同的键和元素类型

问题描述

是否可以对 boost::multi_index_container 中的键和元素使用不同类型的数据结构? GCC 让我编译如下:

struct StructA {
  std::string name;
};

struct StructB {
  int primary;
  int secondary;
};

using mic = 
multi_index_container<
  StructA,indexed_by<
    composite_key< 
      StructB,member< StructB,int,StructB::primary >,StructB::secondary >
>>>;

首先,我不确定上面的代码是否违反了任何一种 multi_index_container 用法。它当然使用不同的元素 (StructA) 和复合索引键 (StructB) 进行编译。其次,我如何插入/放置到这样的容器中?三、如何访问此类容器中的元素?

解决方法

认为这应该如何工作?