I am trying (and failing) to write a type trait that detects Eigen expressions. In other words, I'd like to be able to detect things like A * A + B
etc. where A
and B
are Eigen
matrices/vectors. Currently I'm doing this:
template<typename T>
struct is_matrix_expression : std::false_type
{
};
template<typename Derived> // specialization
struct is_matrix_expression<typename Eigen::MatrixBase<Derived>> :
std::true_type
{
};
Note that Eigen::MatrixBase<Derived>
is a (template) base for all possible Eigen expressions (such as decltype(A * A + B)
etc). However, the general template is being picked out, as it is a better match for something like decltype(A * A + B)
, and not the MatrixBase<Derived>
specialization.
How can I somehow enforce the specialization to be picked out? Or, in other words, enable the specialization for all possible children of Eigen::MatrixBase<Derived>
? I played a bit with SFINAE on std::is_base_of
, but that requires an explicit type and not a template where the type of the expression (in this case Derived
) is not known in advance.
Aucun commentaire:
Enregistrer un commentaire