[eigen] Why do const accessors return by value? |

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: [eigen] Why do const accessors return by value?*From*: Patrick Mihelich <patrick.mihelich@xxxxxxxxx>*Date*: Tue, 31 Mar 2009 12:05:57 -0700*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=hCSWySW1dD5MRjUjcP0BuB9MQ0JhJvsi/xsns6LB66g=; b=f2u+F78rLDSJ0iCO0QNWwRnBMKM/wTzbPE4XMRYBwKGZ1r7S6blbKRhUkBxgYSXU0B hDIqLvYQD8ySvwQgOfMLFs4f0vJ53WuuFF5statk5YgfxUa0aJIDgeBeWuaWDPwyRV+7 C0lG1THSJ1DuBkUtcic2YozKix22N07FLbIqo=*Domainkey-signature*: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=eLRhRSjiPRwNRsTd5ogATxwF8e+Lj9xosWEjhK3ogrOPO9tGiKlnmrPNE6cmwsXPg6 5mtDZdlg6dUTgSjF7Ku+cocueBYvfRkrJG3hDJ9xCBoQmjCiR4hH/5sv4yApCylY1qzn Rr/MdGUzGORiP7DO9Si5B24eKGqWlkVfWUQ5A=

Hi again,

Currently all of the MatrixBase const accessor functions return const Scalar, while the non-const version return (of course) Scalar&. Is there a rationale for returning by value in the const versions instead of const Scalar&? I don't like this inconsistent behavior. Sometimes I want to get a pointer to a chunk of memory in a Matrix so I can pass it to some low-level function, like foo( &mat(r, c) ). This breaks when mat is a const type like const Matrix&. I can also imagine wanting to use Eigen matrices with types that are not trivially cheap to copy (arbitrary precision types, for example), when returning by value may result in an unwanted copy.

Cheers,

Patrick

**Follow-Ups**:**Re: [eigen] Why do const accessors return by value?***From:*Benoit Jacob

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] sse asin implementation** - Next by Date:
**Re: [eigen] Why do const accessors return by value?** - Previous by thread:
**Re: [eigen] Revision 925153 (and a tiny bug, I think)** - Next by thread:
**Re: [eigen] Why do const accessors return by value?**

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