Re: [eigen] Why do const accessors return by value?

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


2009/3/31 Patrick Mihelich <patrick.mihelich@xxxxxxxxx>:
> OK, right. But you do not always have to use the lowest-common-denominator
> behavior (return by value). MatrixBase knows the Derived type and can return
> by const-reference for Derived types with dense storage (Matrix, Map).

ah right, good idea. I'll look into that.

> OK but this is more verbose, and it's rather surprising that it doesn't do
> the same thing as m(i,j) or even m.coeff(i,j). I do not think Matrix should
> override the coeff() methods from MatrixBase with different signatures; more
> generally I'd suggest that for any MatrixBase method foo, m.foo() and
> m.derived().foo() should always behave identically.

I understand. Good idea. I do that and I update you....

> BTW, there is a mistake in MapBase: const Scalar coeff(int index) const
> should return const Scalar&.

woops, good catch !

>> That's another issue. But the above-mentioned fact that xpressions
>> have no choice but to return by value, is unavoidable. So I think that
>> the best solution then, is that the "heavy numeric types" in question
>> be endowed with a copy-on-write mechanism so that these copies become
>> shallow copies.
>
> Making the accessor return types smarter I think is much simpler.

Yes but it doesn't solve that latter problem. Nontrivial xprs will
always have to return values, so copy-on-write is really useful for
big types, unless the compiler is clever enough.

Cheers,
Benoit



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