|Re: [eigen] MatrixBase::swap -- why const?|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] MatrixBase::swap -- why const?
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Fri, 5 Jun 2009 23:38:26 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=mjvZ7Hp6A1kgtCpsv3aVMImapxRaQ3h/2lepbSckpKQ=; b=vMHs0bVismAC8JkMECtG7M4rRVbzdZwSTSCnA5jxia9TmQAhdSb3VDPl0MMPphZFFz 99jjdOWaXqAWQIhxbfsdhdFK0ImRIXUV6NhhYwzqecdi6Ui/o92rHR4hV5v28e0YMJ8/ HmTL5BV9pu5mPnDQGJ2FBQoMlRAeg6vnr2J5A=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=AkokWz/Q8T8hdVXayzO8LOgiUmSFKNkKTIWjvG+kBb8AzwpcBxTUo9V8fPxeJ3u52k FQ1MgI3aWxjWKqPBLGRBsjI3u1kCR4Bh81uxA93N/fgEqL9oIYggpHri3wffcPBJ11Bi uO825MkOji/QqBgrVLDl91Jxcwx3Rc9mqjoi4=
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
So, if possible, a proper implementation of swap() could proceed by
taking plain matrices by reference, while taking all other expressions
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.
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:
> 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....
> 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.