fork download
  1. #include "stdio.h"
  2.  
  3. namespace A {
  4. template <typename T>
  5. struct Key {
  6. T value;
  7. };
  8.  
  9. template <typename T>
  10. bool operator==(const Key<T> &a, const Key<T> &b) {
  11. return a.value == b.value;
  12. }
  13. }
  14. namespace B {
  15. template <typename KT, typename VT>
  16. struct MappedVal {
  17. VT value;
  18. A::Key<KT> key;
  19. };
  20.  
  21. template <typename KT, typename VT>
  22. bool operator==(const MappedVal<KT, VT> &a, const MappedVal<KT, VT> &b) {
  23. return (a.key == b.key && a.value == b.value);
  24. }
  25. }
  26.  
  27. int main() {
  28. A::Key<short> key1, key2;
  29. key1.value = 1;
  30. key2.value = 1;
  31.  
  32. B::MappedVal<short, double> val1, val2;
  33. val1.key = key1;
  34. val1.value = 12.41;
  35.  
  36. val2.key = key1;
  37. val2.value = 12.41;
  38.  
  39. bool test1 = (key1 == key2);
  40. bool test2 = (val1 == val2);
  41.  
  42. printf("key1 == key2: %s", (test1 ? "true" : "false"));
  43. printf("val1 == val2: %s", (test2 ? "true" : "false"));
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
key1 == key2: trueval1 == val2: true