SHARE
TWEET

Untitled

a guest Feb 14th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <unordered_set>
  2.  
  3. using namespace std;
  4.  
  5. struct MyType {
  6.     int val;
  7. };
  8.  
  9. struct MyTypeEquals {
  10.     using is_transparent = void;
  11.     bool operator()(MyType const& l, MyType const& r) const {
  12.         return l.val == r.val;
  13.     }
  14.     bool operator()(int const l, MyType const& r) const {
  15.         return l == r.val;
  16.     }
  17.     bool operator()(MyType const& l, int const r) const {
  18.         return l.val == r;
  19.     }
  20. };
  21.  
  22. struct MyTypeHash {
  23.     using transparent_key_equal = MyTypeEquals;
  24.  
  25.     std::size_t operator()(MyType const& s) const {
  26.         return hash<int>()(s.val);
  27.     }
  28.  
  29.     std::size_t operator()(int const& s) const {
  30.         return hash<int>()(s);
  31.     }
  32. };
  33.  
  34. int main()
  35. {
  36.     unordered_set<MyType, MyTypeHash, MyTypeEquals> mytype_set;
  37.     mytype_set.insert(MyType{1});
  38.     mytype_set.equal_range(1);
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top