fork download
  1. #include <iostream>
  2. #include <functional>
  3. #include <unordered_set>
  4.  
  5. struct X
  6. {
  7. std::string key_;
  8. };
  9.  
  10. int main() {
  11. std::unordered_set<X,
  12. std::function<size_t(const X&)>,
  13. std::function<bool(const X&, const X&)> > s{
  14. 5, // initial bucket count
  15. [](const X& x) { return std::hash<decltype(x.key_)>()(x.key_); },
  16. [](const X& lhs, const X& rhs) { return lhs.key_ == rhs.key_; }
  17. };
  18. s.insert({"one"});
  19. s.insert({"two"});
  20. s.insert({"three"});
  21. for (auto& x : s)
  22. std::cout << x.key_ << '\n';
  23. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
three
two
one