unordered_set 编译问题

lqylqylqyymfx 2013-03-02 12:47:25
下面的code可以编译:
unordered_set<int> my_set;
/*
………………………………
*/
for(auto it = my_set.begin(); it != my_set.end(); ++it) {
int some_int = *it;
}

但是下面的通不过编译:

unordered_set<vector<int> > my_set;
/*
………………………………
*/
for(auto it = my_set.begin(); it != my_set.end(); ++it) {
vector<int> some_int = *it;
}

求助!
...全文
214 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
taodm 2013-03-02
  • 打赏
  • 举报
回复
你还是老老实实用Set吧。
ri_aje 2013-03-02
  • 打赏
  • 举报
回复
需要自己提供 hasher,下面的例子只是语法过关,hasher 具体怎么写依赖于你的应用。

#include <unordered_set>
#include <vector>
using namespace std;

namespace std
{
 template <>
 struct hash <std::vector<int>>
 {
  using result_type   = size_t;
  using argument_type = std::vector<int>;

  size_t operator () (std::vector<int>const& key) const
  {
   // hasher for vector implementation.
   return 0;
  }
 };
}

int main ()
{
 unordered_set<vector<int>> my_set;
 for(auto it = my_set.begin(); it != my_set.end(); ++it) {
  int some_int = (*it).front();
 }
}

64,677

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧