首页 > 解决方案 > 如何制作自定义字符串的 std::unorder_set 类型?

问题描述

假设我有一个自定义字符串,如 type:

struct MyType {
  std::string str_;
  int somethingElse;
}

现在,我知道如何使它在 std::set 中可用 - 只需提供<运算符。

我怎样才能使用它std::unordered_set什么时候应该基于std::string str_成员?

std::unordered_set<MyType> um;

更新:我已经看到了这个答案:C++ unordered_map using a custom class type as the key 它看起来有些过时了(c++11 ?)并且还担心map

标签: c++hashc++17unordered-map

解决方案


推荐阅读