I have a template class, MyClass<...>
, which has member variables of type Eigen::Matrix<X, N, M>
where X
is the native template parameter for a particular instance of MyClass
.
Assuming that my private variable of the aforementioned type is myVar
. In order to make the setMyVar
function generic, I define it as a template function like
template <typename U>
void setMyVar(const Eigen::Matrix<U, 3, 1>& newVal) const {
// myVar is of type Eigen::Matrix<T, 3, 1>
myVar = newVal.cast<T>();
}
My question is whether Eigen skips the casting operation in case T == U
.
I am in particular interested in learning the behavior of Eigen in such a scenario. Otherwise I am very well aware of alternative solutions such as using SFINAE to force to compiler to choose among the right overloads of setMyVar
or use if constexp (std::is_same_v<T, U) {...} else {...}
(for c++17) to decide whether a cast is required or not during compile time.
Thanks