F. *_* P. 9 c++ boost stl unordered-set c++11
我想unordered_set
在一个项目中使用.
但是,它的文档要么不完整,要么只是技术参考,没有示例.
任何人都可以提供与处理它的在线资源的链接吗?书籍也欢迎,最好免费.Google搜索没有带来任何价值.
谢谢!
最常见用例的代码:
#include <boost/unordered_set.hpp>
using boost::unordered_set;
using std::string;
using std::cout;
using std::endl;
int main (void)
{
// Initialize set
unordered_set<string> s;
s.insert("red");
s.insert("green");
s.insert("blue");
// Search for membership
if(s.find("red") != s.end())
cout << "found red" << endl;
if(s.find("purple") != s.end())
cout << "found purple" << endl;
if(s.find("blue") != s.end())
cout << "found blue" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
产量
found red
found blue
Run Code Online (Sandbox Code Playgroud)
更多信息
http://www.cplusplus.com/reference/unordered_set/unordered_set/find/
关于它的文档很少,因为它的行为完全相同std::set
,除了它需要散列和等于函数而不是比较函数.只需查看示例std::set
,并替换它们,std::unordered_set
你应该没问题.
如果您需要编写散列函数,则文档中有一些示例,即此示例.