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