UPDATED: I managed to get it to work after I googled around and read the doxygen comments in code. Problem was that I missed the cast before using res
Based on @Azoth answer (whom I would like to give the whole credit, anyway), I improved the template a bit to
Eigen::Array
(rather than just Eigen::Matrix
);Eigen::Vector3f
).This is the result:
namespace cereal
{
template inline
typename std::enable_if, Archive>::value, void>::type
save(Archive & ar, Eigen::PlainObjectBase const & m){
typedef Eigen::PlainObjectBase ArrT;
if(ArrT::RowsAtCompileTime==Eigen::Dynamic) ar(m.rows());
if(ArrT::ColsAtCompileTime==Eigen::Dynamic) ar(m.cols());
ar(binary_data(m.data(),m.size()*sizeof(typename Derived::Scalar)));
}
template inline
typename std::enable_if, Archive>::value, void>::type
load(Archive & ar, Eigen::PlainObjectBase & m){
typedef Eigen::PlainObjectBase ArrT;
Eigen::Index rows=ArrT::RowsAtCompileTime, cols=ArrT::ColsAtCompileTime;
if(rows==Eigen::Dynamic) ar(rows);
if(cols==Eigen::Dynamic) ar(cols);
m.resize(rows,cols);
ar(binary_data(m.data(),static_cast(rows*cols*sizeof(typename Derived::Scalar))));
}
}