Registered Member
|
I have a templated function taking in Eigen matrices that works great,
template<typename T> void foo(const Eigen::Matrix<var<T>, Eigen::Dynamic, 1>& v1, const Eigen::Matrix<var<T>, Eigen::Dynamic, 1>& v2) { ... } In particular, T gets deduced from the arguments so calling the function is nice and clean. Now I was playing with extending the function to be compatible with expression templates via http://eigen.tuxfamily.org/dox/TopicFun ... Types.html, template<typename T, typename DerivedA, typename DerivedB> void foo(const Eigen::MatrixBase<DerivedA>& v1, const Eigen::MatrixBase<DerivedA>& v2) { ... } This works as expected, but T can no longer be deduced through the expression templates which makes calling the function a bit of a pain. Is there anyway to deduce T here or will the expression templates forever hide that info? Thanks. |
Registered Member
|
All MatrixBase<X> types have a typedef Scalar which exposes the underlying scalar. Thus, if you have
In your case, Scalar would be var<T> so your var type needs to expect the underlying T in some way. |
Registered Member
|
Great, thanks. We were able to make this work using Eigen::MatrixBase<DerivedA>::Scalar
and some enable_if templating magic to get the signatures right. |
Moderator
|
Tip: "typename DerivedA::Scalar" is shorter.
|
Registered users: Baidu [Spider], Bing [Bot], Google [Bot]