I have a function for which I have several templated overloads. I which to add an Eigen overload to it. I want to be general such as to be able to accept any Eigen matrix. Therefore I use Eigen::MatrixBase<T>
. The problem kicks in with the overload, where the compiler fails to recognise the closest match with Eigen::MatrixBase<T>
. Here is my code:
#include <iostream>
#include <Eigen/Eigen>
template <class T>
void foo(const Eigen::MatrixBase<T> &data)
{
std::cout << "Eigen" << std::endl;
}
// ... several other overloads
template <class T>
void foo(const T &data)
{
std::cout << "other" << std::endl;
}
int main()
{
Eigen::VectorXd a(2);
a(0) = 0.;
a(1) = 1.;
foo(a);
}
Whereby the output is other
. How can I make the Eigen overload such that it is the closest match for any Eigen matrix?