Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unordered_set>
- using namespace std;
- struct MyType {
- int val;
- };
- struct MyTypeEquals {
- using is_transparent = void;
- bool operator()(MyType const& l, MyType const& r) const {
- return l.val == r.val;
- }
- bool operator()(int const l, MyType const& r) const {
- return l == r.val;
- }
- bool operator()(MyType const& l, int const r) const {
- return l.val == r;
- }
- };
- struct MyTypeHash {
- using transparent_key_equal = MyTypeEquals;
- std::size_t operator()(MyType const& s) const {
- return hash<int>()(s.val);
- }
- std::size_t operator()(int const& s) const {
- return hash<int>()(s);
- }
- };
- int main()
- {
- unordered_set<MyType, MyTypeHash, MyTypeEquals> mytype_set;
- mytype_set.insert(MyType{1});
- mytype_set.equal_range(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement