正如我刚刚在in my other question中学到的,我可以对结构使用composite_key,它有一个std::vector和一个整数。现在我的问题是:我能以某种方式使用它来处理hashed_indecies吗?
下面是一个类似于THIS的示例
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::vector<int>不是合适的散列键。我是否可以将这段代码放在一个优雅的包装器中(或类似的东西),以便从my_vec的每个条目中生成一个散列键?
发布于 2009-11-09 22:25:04
使用您的建议here中的代码片段。应该能行得通。我已经在那里添加了我的评论。
发布于 2009-11-09 22:42:56
如果你希望向量是可散列的,你可以用namespace std编写一个hash<vector<int> >函数,让它散列成你喜欢的任何方式(提示:在某些应用程序中,你可能只需要散列前几个元素就可以了)。这应该会使std::hash_set<vector<int> >工作,我认为您的更复杂的容器也是如此。
https://stackoverflow.com/questions/1701022
复制相似问题