decltype/dt2.cc - A sample use of decltype in a function template: matrix plus. | Lecture 2 - slide 24 : 29 Program 2 |
// Illustrates that the return type of th plus function depends of the type of the sume of 'a T-value' and an 'U-value'. // Compiles with g++ -c dt2.cc -std=c++11 // The example comes from The C++ Language (4ed) page 165. template<typename T> class Matrix; template<typename T, typename U> auto plus(const Matrix<T>& a, const Matrix<U>& b) -> Matrix<decltype(T{}+U{})>;