fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct ghash {
  5. unsigned code; // all the values you need here
  6. // may be some additional common hash functions
  7. };
  8. ostream& operator<< (ostream&os, ghash x) { // for example a general display function
  9. return os<<"HASH "<<x.code;
  10. }
  11.  
  12. struct X {
  13. int k;
  14. int l;
  15.  
  16. operator ghash () { // conversion oeprator
  17. ghash rh;
  18. rh.code = (unsigned) k^l; // compute the hash
  19. return rh;
  20. }
  21. };
  22.  
  23. int main() {
  24. X myx;
  25. myx.k=-1;
  26. myx.l=20;
  27.  
  28. ghash hx = myx; // implicit converstion from X to its hash
  29. cout<<hx <<endl;
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
HASH 4294967275