I'm writing a templated sparse container class and would like to check if incoming data equals zero. The data type will either be an integer or a fixed size Eigen type.
#include <Eigen/Core>
template<typename T>
struct SparseContainer
{
void insert(const T& value)
{
if(isZero(value))
return;
// ...
}
};
int main(int argc, char* argv[])
{
SparseContainer<int> a;
a.insert(1);
SparseContainer<Eigen::Vector2i> b;
b.insert(Eigen::Vector2i(1, 0));
}
How do I provide the isZero() function so that it works with integers and Eigen types by default, and can be extended by users of the class for their own types. I don't use boost, but C++11(i.e. std::enable_if
) is ok.