TemplateKeyword_flexible.cpp revision c981c48f5bc9aefeffc0bcb0cc3934c2fae179dd
1#include <Eigen/Dense>
2#include <iostream>
3
4using namespace Eigen;
5
6template <typename Derived1, typename Derived2>
7void copyUpperTriangularPart(MatrixBase<Derived1>& dst, const MatrixBase<Derived2>& src)
8{
9  /* Note the 'template' keywords in the following line! */
10  dst.template triangularView<Upper>() = src.template triangularView<Upper>();
11}
12
13int main()
14{
15  MatrixXi m1 = MatrixXi::Ones(5,5);
16  MatrixXi m2 = MatrixXi::Random(4,4);
17  std::cout << "m2 before copy:" << std::endl;
18  std::cout << m2 << std::endl << std::endl;
19  copyUpperTriangularPart(m2, m1.topLeftCorner(4,4));
20  std::cout << "m2 after copy:" << std::endl;
21  std::cout << m2 << std::endl << std::endl;
22}
23