Boost多指数:向量的复合键和int的散列索引 [英] Boost Multi-Index : Composite key of vector and int for hashed indices

查看:128
本文介绍了Boost多指数:向量的复合键和int的散列索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我刚刚得知在<一个href=\"http://stackoverflow.com/questions/1699704/boostmultiindexcontainer-with-randomaccess-and-orderedunique\">in我的其他问题,我可以使用 composite_key 为一个结构,它有一个的std ::矢量和的整数。现在的问题是:我可以使用这个以某种方式hashed_indecies工作

as I've just learned in in my other question, I could use a composite_key for a struct, which has a std::vector and an integer. Now my question is: Can I use this somehow to work with hashed_indecies?

下面类似<一个例子href=\"http://www.boost.org/doc/libs/1%5F40%5F0/libs/multi%5Findex/doc/tutorial/key%5Fextraction.html#composite%5Fkeys%5Fhash\"相对=nofollow>这:

struct unique_property
{
  //the pair of int and std::vector<int> shall be unique
  int my_int;
  std::vector<int>  my_vec;
};

typedef multi_index_container<
  unique_property,
  indexed_by<
    hashed_unique< // indexed by my_int and every entry of my_vec
      composite_key<
        street_entry,
        member<unique_property,int,&unique_property::my_int>,
        member<unique_property,std::vector<int>,&unique_property::my_vec>
      >
    >,
    random_access< >
  >
> property_locator;

问题是(当然),一个的std ::矢量&lt;&INT GT; 是没有合适的散列键。我可以把这个code在优雅的包装(或类似的东西),以从每个条目的哈希键 my_vec 以及

The problem is (of course) that a std::vector<int> is no suitable hash-key. Can I put this code in an elegant wrapper (or something like that), to produce a hash-key from every entry of my_vec as well?

推荐答案

使用code从您的建议<片段href=\"http://stackoverflow.com/questions/1699704/boostmultiindexcontainer-with-randomaccess-and-orderedunique/1700899#1700899\">here.它应该工作。我有我的补充意见。

Use code snippet from your suggestion here. It should work. I've added my comments there.

这篇关于Boost多指数:向量的复合键和int的散列索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆