Public API to handle function arguments
@ggael
Submitted by Gael GuennebaudAssigned to Nobody
Link to original bugzilla bug (#111)
Description
This comes from the end of the thread: "new tutorial on writing functions taking Eigen types as paramters".
The goal is to provide a simple and stable API to deal with generic function arguments such as:
template<Derived> void foo(const MatrixBase<Derived>& mat)
{
}
where Derived can be any Eigen expression. This will become even more important once bug #99 (closed) fixed.
If mat is used only once in the function, then it's fine, the user has nothing to do.
If mat is used N times, then the expression will be evaluated N times that is not good.
Even worse, if the function foo directly access to the coeff of the matrix mat, e.g., for each i,j do something with mat(i,j)..., then compilation might fail if the expression has to be evaluated first (e.g., if it contains products, or result of a solve operation, etc.).
In the previously mentioned ML thread we proposed something like:
template<int N> struct NestedForMultipleAccess {
typedef typename ei_nested<Derived, N> Type;
};
typename XprType::template NestedForMultipleAccess<N>::Type myvar(myarg);
or just:
typename XprType::template Nested<>::Type myvar(myarg);
typename XprType::template Nested<1>::Type myvar(myarg);
typename XprType::template Nested<2>::Type myvar(myarg);
typename XprType::template Nested<Dynamic>::Type myvar(myarg);
and maybe some shortcut to avoid the need of the template keyword most of the time:
typedef typename ei_nested<Derived,1>::type Nested;
typedef typename ei_nested<Derived,2>::type NestedForTwoAccess;
typedef typename ei_nested<Derived,Dynamic>::type NestedForMultipleAccess;
alternative names: NestedOnce, NestedTwice, NestedManyTimes ???
All these names are based on the word "Nested" which is actually not very good here because the 1) the expression is not really nested here, and 2) after bug #99 (closed) implemented, this "Nested" mechanism won't be based on our internal::nested anymore.
So name more focused on the task of handling function arguments would be better suited I guess.