Re: [eigen] Return type of eval() for non-plain-object should not be const qualified

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


I see. Just to add to the discussion, if normalize() is defined as "r-value reference qualified", i.e., class vec { normalize() & {..}}, then the compiler won't allow it being called on a temporary object. 







On Mon, Jul 24, 2017 at 10:03 PM Gael Guennebaud <gael.guennebaud@xxxxxxxxx> wrote:

Hi,

IIRC, the rationale was to prevent calling non-const methods on temporary objects, like:

 (....).eval().normalize()

At that time, C++11 did not existed, but nowadays, we could reconsider this choice to favor move assignment.

Gael. 

On Sun, Jul 23, 2017 at 10:03 AM, Yuanchen Zhu <yuanchen.zhu@xxxxxxxxx> wrote:
Hi all, 

I want to check with the list if this is as intended (and I'm missing some big picture) or a bug:

Currently T::eval() either returns a const reference if T is a plain object, which is fine, or a const object if T is an _expression_. I think evaluating an _expression_ should return just an object, not a const qualified object. This enables move assignment optimization that takes the result from evaluation, and return it directly, without creating a temporary copy.

The relevant line is:

 typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType;

in DenseBase.h




Thanks,
Yuanchen




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