mercredi 18 avril 2018

Template parameters that depend on other template parameters?

I have found a few similar questions (e.g. this), but none of them really answer mine. Consider this code snippet:

template<unsigned int rows, unsigned int cols,typename arrtype>
class Variance
{
   double f(const arrtype &);
};

template<unsigned int rows, unsigned int cols>
double Variance<rows,cols,Eigen::Matrix<double,rows,cols>>
    ::f(const Eigen::Array<double,rows,cols> & M) 
{
  //do stuff
}

As you can see in the specialization, the type arrtype will depend on rows and cols. The code above results in a compiler error (g++ 5.4.0):

invalid use of incomplete type ‘class Variance<rows, cols, Eigen::Matrix<double, rows, cols> >

I have tried typename arrtype<rows, cols> in the template declaration, but then it complains that arrtype is not a type, which makes sense.

What is the proper way to use templated types that depend on other templated types?

Aucun commentaire:

Enregistrer un commentaire