mardi 17 mars 2020

Cant find operator>>(std::istringstream, Eigen) although I define it

I am trying to use an Eigen class inside a data container (Data<T> with T begin an Eigen::Matrix<...>). At some point, the Data<> class tries to call operator>>(std::istringstream, Eigen::Matrix<...>) which fails because that operator is not defined.

I have implement it myself, in several flavours (template based and non templated based). This are my trials:

std::istringstream &operator>>(std::istringstream &str, Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &t)
{
    return str;
}

template <typename T>
std::istringstream &operator>>(std::istringstream &str, Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> t)
{
    return str;
}

std::istringstream &operator>>(std::istringstream &str, Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> t)
{
    return str;
}

std::istringstream &operator>>(std::istringstream &str, Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> &t)
{
    return str;
}

std::istringstream &operator>>(std::istringstream &str, Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> &t)
{
    return str;
}

std::istringstream &operator>>(std::istringstream &str, Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> t)
{
    return str;
}

I dont want to do anything inside the operator, at least for now. Basically, what the library does is to read an xml file and build the appropiate object inside Data<> calling the operator>>, but I dont need that, so empty implementation.

Still, the compiler complains it can't find the operator with the following error:

SofaFramework/sofa/core/objectmodel/Data.h:553:10: error: no match for ‘operator>>’ (operand types are ‘std::istringstream’ {aka ‘std::__cxx11::basic_istringstream<char>’} and ‘Eigen::Matrix<double, -1, -1>’)
In file included from /usr/include/c++/9.3.0/sstream:38

I am not sure what can be wrong here. Any idea of what is happening?

Aucun commentaire:

Enregistrer un commentaire