fork download
  1. #include <iostream>
  2. #include <unordered_set>
  3. #include <functional>
  4. #include <cassert>
  5.  
  6. struct TTest {
  7. char essence;
  8. mutable void* aux_nohash;
  9.  
  10. bool operator == (const TTest& other) const { if(!aux_nohash) aux_nohash = NULL; return this->essence == other.essence; }
  11. };
  12.  
  13. namespace std {
  14. template<> struct hash<TTest> {
  15. size_t operator() (const TTest& val) const { return std::hash<char>()(val.essence); };
  16. };
  17. } // namespace std
  18.  
  19. int main() {
  20. TTest dick1 {'1', NULL};
  21. TTest dick2 {'2', &stdin};
  22. TTest dick3 {'3', NULL};
  23. TTest dick4 {'2', &dick1};
  24. std::hash<TTest> hash;
  25. assert(hash(dick1) != hash(dick2));
  26. assert(hash(dick2) == hash(dick4));
  27. assert(hash(dick1) != hash(dick3));
  28.  
  29. std::unordered_set<TTest> your_anus;
  30. your_anus.insert(dick1);
  31. your_anus.insert(dick2);
  32. your_anus.insert(dick3);
  33. assert(your_anus.count(dick4) < 1);
  34. }
  35.  
Runtime error #stdin #stdout 0s 3016KB
stdin
Standard input is empty
stdout
Standard output is empty