fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. namespace X
  5. {
  6. template<typename T> struct Mat { typedef T value_type; };
  7. template<typename T> struct MatExpr {};
  8.  
  9. template<typename T>
  10. MatExpr<T> prod(Mat<T> const& A, Mat<T> const& B) { return MatExpr<T>(); }
  11. }
  12.  
  13. struct Mat2 {};
  14.  
  15. template<typename T>
  16. X::Mat<T> prod(const X::Mat<T> &A, const Mat2 &B) { return X::Mat<T>(); }
  17.  
  18.  
  19. template<typename T1, typename T2>
  20. auto operator *(const T1 &a, const T2 &b) -> decltype(X::prod(a, b))
  21. {
  22. cout << __PRETTY_FUNCTION__ << '\n';
  23. return X::prod(a, b);
  24. }
  25.  
  26. template<typename T1, typename T2>
  27. auto operator *(const T1 &a, const T2 &b) -> decltype(::prod<typename T1::value_type>(a, b))
  28. {
  29. cout << __PRETTY_FUNCTION__ << '\n';
  30. return ::prod(a, b);
  31. }
  32.  
  33. int main()
  34. {
  35. X::Mat<int> a, b;
  36. a * b;
  37. Mat2 c;
  38. a * c;
  39. }
  40.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
decltype (X::prod(a, b)) operator*(const T1&, const T2&) [with T1 = X::Mat<int>; T2 = X::Mat<int>; decltype (X::prod(a, b)) = X::MatExpr<int>]
decltype (prod<typename T1::value_type>(a, b)) operator*(const T1&, const T2&) [with T1 = X::Mat<int>; T2 = Mat2; decltype (prod<typename T1::value_type>(a, b)) = X::Mat<int>; typename T1::value_type = int]