[eigen] "plain": a new keyword for auto with implicit evaluation

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,

as you all know here 'auto' does not always play well with Eigen, especially for users who are not well aware of _expression_ templates [1]. So what about an "auto" like keyword but with implicit evaluation:

    plain C = A * b;

which would have the same behavior as:

   auto C = (A*B).eval();

??

Actually, I just realized this is already possible in C++17 thanks to template deduction guides. The proof-of-concept implementation of such a "plain" is embarrassingly simple:

namespace Eigen {
template<typename T>
struct plain : T::PlainObject {
  using Base = typename T::PlainObject;
  using Base::operator=;
  plain(const T& x) : Base(x) {}
};
}

Thats's all! 


Ok, to be fair this is not strictly equivalent to auto+eval() because here decltype(C) != decltype(A*B)::PlainObject, but at a first glance this should not make much difference. This look to simple though. Am I overseeing some severe limitations?

Of course, you cannot write plain& or plain&& as you would do with auto but I cannot find an example where this would make a practical limitation compared to auto+eval().

As a side note, yes we should add deduction guides for Array,Matrix,SparseMatrix from expressions, but that's another topic.

Cheers,
Gaël



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/