如何在c++中找到两个std::hash_set的交集
How to find the intersection of two std::hash_set in C++?
STD库是否提供任何函数允许我找到两个STD::hash_set的交集?
我尝试使用std::set_intersection
,但我得到断言错误与Expression: sequence not ordered
,有任何工作围绕这一点?
#include <hash_set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
int main()
{
std::hash_set<std::string> h1;
h1.insert("NoMainDraw");
h1.insert("NoLight");
h1.insert("Random");
std::hash_set<std::string> h2;
h2.insert("NoLight");
std::vector<std::string> groupDifference;
std::set_intersection(h1.cbegin(), h1.cend(),
h2.cbegin(), h2.cend(),
std::back_inserter(groupDifference));
for(const std::string& i : groupDifference)
{
std::cout << i << std::endl;
}
}
你必须迭代一个map
做查找在另一个。没有标准库算法
相关文章:
- 对自定义类使用 std::hash<uint64_t>
- std::hash<std::string> 可以为不同的字符串返回相同的值吗?
- C++std::hash实现总是确定性的吗
- std::hash for std::chrono::duration
- Hash for a std::pair, for use in an unordered_map
- 为什么在这种特殊情况下不需要将 std::hash() 的专用化注入到 std 命名空间中?
- "The C++ Library doesen't provide a hash for this type." - 在 std::unordered_map 中使用自己的类
- 为什么不区分大小写适用于 std::unordered_set的 std::hash 函数?
- 错误:未使用不完整的类型'struct std::hash<>'无效
- 无法专门化 std::hash 以unordered_map存储自定义类型
- 为模板类嵌套类定义 std::hash 时出现编译错误
- Return value of std::hash ofr (x86/x64)
- 明确的专业化;'std::hash<_Kty>' 已被实例化
- STD :: HASH :: operator() - 例外保证
- STD :: HASH专业化仍然由STD :: Unordered_map未使用
- C++11:是否有理由为什么某些常规类型不应该专门使用“std::hash”
- 定义 std::hash<std::function>
- boost::hash/std::tr1::hash 不为复制的 const char* 返回相同的哈希
- 使用 std::hash<std::thread::id>()(std::this_thread::get_id())
- 覆盖 std::hash<std::string> 以使用 Google 的城市哈希