Re: [eigen] MatrixBase::swap -- why const?

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


Actually, I just thought of something stupid...

why the hell do I insist on storing these temporary expression objects
by reference? An expression object, such as the return value of
"matrix.row(i)", is lightweight, so it is harmless to store by value
(and the compiler then does a good job at optimizing that).

On the other hand, plain matrices must be stored by reference, but
then they're not temporaries so we may pass them by non-const
references.

So, if possible, a proper implementation of swap() could proceed by
taking plain matrices by reference, while taking all other expressions
by value.

I remember i tried that a long time ago and gave up, but that doesn't
have to mean it's impossible, I just was confused at that time.

Cheers,
Benoit

2009/6/4 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
> i don't have a good solution for this one.
>
> the problem is that c++ doesn't seem to allow to pass a non-constant
> reference to a temporary.
>
> so when we do:
>
> matrix.row(i).swap(matrix.row(j))
>
> we are passing the temporary matrix.row(j) object to swap, c++ doesn't
> seem to allow to pass it as a non-const reference
>
> I'd love to hear if i was completely missing something....
>
> Benoit
>
> 2009/6/4 Mark Borgerding <mark@xxxxxxxxxxxxxx>:
>> I'm struggling to understand
>>   template<typename OtherDerived/*, int OtherMode*/>
>>   void swap(const MatrixBase<OtherDerived>& other)
>>
>> Why is "other" a const reference? It is modified by the call, no?
>> This seems like a violation of interface contract.
>>
>>
>>
>>
>>
>



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