I have a Matrix class that comes from the Eigen template:
template<typename T,
int _Rows = Eigen::Dynamic,
int _Cols = Eigen::Dynamic>
class Matrix : public Eigen::Matrix<T, _Rows, _Cols>
I need to use this type as the key for the container std::map, so I need a comparator object. For this purpose, I would like to specialize std::less. A project that does not compile looks like this so that you understand:
template<typename Matrix<typename T,
int _Rows = Eigen::Dynamic,
int _Cols = Eigen::Dynamic> > >
struct less
{
bool operator()(const Matrix<T,
Rows,
Cols>& lhs,
const Matrix<T,
Rows,
Cols>& rhs) const;
{
Matrix<T,
Rows,
Cols>::const_iterator lhsIt = lhs.begin();
Matrix<T,
Rows,
Cols>::const_iterator rhsIt = rhs.begin();
for (;
lhsIt != lhs.end();
++lhsIt, ++rhsIt)
{
if (*lhsIt < *rhsIt)
{
return true;
}
}
return false;
}
};
The problem is that I want to specialize std::lesswith a template. What is the correct way to code this? Do I need to resort to specialized specialization?
I will also need to specialize in a std::hashsimilar way to be able to use std::map.