|Re: [eigen] Why do const accessors return by value?|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Why do const accessors return by value?
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Tue, 31 Mar 2009 23:46:31 +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=9Md8jj+lcmzVxkozcWXxnusG5wnmiOIYuqtGwf0SLg0=; b=wPJALWJhOmxacRlj4wrrqsva72Kr551HCU4mcHmYiWz4yC/0sR4nLE1QqqSR3sKTvc vt/xIfYyl7umCvtMrLgdjVpe+dB54/r6WXtM1mzY0IkO+0KzQ3vQ77tc8GGFLIJxaMqq C6Sayywr2JSUJmCaDrJoH8aBfT1xuWj36qh1o=
- 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=BLSANG+1muWdjIzUALjReg/qlC/6G9yrkdEEt1/hDNGatsipIScI+jQT/ihLBTYXuF 4aY/OcTzA5iPkaW6kF7fp7tIMFeTuZzVVFF5LqpX6ceOYz5x+KlPJkN2FHpbwa7nae93 47m8VV+UciPZ7zVazDy6p+JKtfSTfk81LYx4I=
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.