fork download
  1. #include <iostream>
  2.  
  3. template <typename D>
  4. struct MatrixBase {};
  5.  
  6. struct Matrix: MatrixBase<Matrix> {};
  7.  
  8. template <typename L, typename R>
  9. struct AddOp: MatrixBase<AddOp<L, R>> {};
  10.  
  11. template <typename L, typename R>
  12. AddOp<L, R> operator+(MatrixBase<L>, MatrixBase<R>) { return AddOp<L, R>(); }
  13.  
  14.  
  15. #define PRINT_MY_NAME std::cout << __PRETTY_FUNCTION__ << '\n'
  16.  
  17. template<typename Derived>
  18. void f(const MatrixBase<Derived>&) // (1)
  19. {
  20. PRINT_MY_NAME;
  21. }
  22.  
  23. template<typename Derived>
  24. void f(MatrixBase<Derived>&&) // (2)
  25. {
  26. PRINT_MY_NAME;
  27. }
  28.  
  29. int main()
  30. {
  31. Matrix A;
  32.  
  33. f(A); // invokes (1)
  34. f(A + A); // invokes also (1) !!!
  35. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
void f(const MatrixBase<L>&) [with Derived = Matrix]
void f(MatrixBase<L>&&) [with Derived = AddOp<Matrix, Matrix>]