fork download
  1. #include <type_traits>
  2.  
  3. template <typename> struct IsBase : std::false_type {};
  4.  
  5. template <typename Self>
  6. struct Base {
  7. Base& operator()() {
  8. return *this;
  9. };
  10.  
  11. template <typename Other,
  12. typename = typename std::enable_if<std::is_same<Other, Self>::value ||
  13. IsBase<Other>::value>::type>
  14. Self operator+(const Other& other) const {
  15. return static_cast<const Self&>(*this);
  16. }
  17. };
  18.  
  19. template <typename X> struct IsBase<Base<X>> : std::true_type {};
  20.  
  21.  
  22. struct D1 : Base<D1> {};
  23. struct D2 : Base<D2> {};
  24.  
  25.  
  26. int main() {
  27. D1 d1;
  28. D2 d2;
  29. d1 + d1;
  30. d2 + d2;
  31. d1() + d2();
  32. d1 + d2;
  33. }
  34.  
  35.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:32:10: error: no match for 'operator+' in 'd1 + d2'
stdout
Standard output is empty