digitalmars.D.learn - front doesn't compile for arrays of immutable data
- Roman D. Boiko (16/16) Jun 25 2012 import std.range;
- Roman D. Boiko (10/10) Jun 25 2012 @property ref T front(T)(T[] a)
- Timon Gehr (3/11) Jun 25 2012 It should always be possible to do so. What you are experiencing seems
- Roman D. Boiko (5/7) Jun 25 2012 I couldn't find it reported before. The closest are:
- Roman D. Boiko (2/9) Jun 25 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8297
- Jonathan M Davis (3/14) Jun 25 2012 What do you mean that it's not possible? What's not possible about it?
- Roman D. Boiko (3/19) Jun 25 2012 Looks like I came to wrong conclusions, so my statement from
- Kenji Hara (6/22) Jun 25 2012 This is a bug of the compiler, and it is already filed.
import std.range; struct Element { //immutable // uncomment to break compilation int _i; this(int i) { _i = i; } } void main() { auto arr = [Element.init]; arr.front; } Declaring _i immutable yields the following compilation error: /usr/include/x86_64-linux-gnu/dmd/phobos/std/array.d(460): Error: a[0LU] isn't mutable sample.d(11): Error: template instance std.array.front!(Element) error instantiating Is this a bug, or I misunderstand something?
Jun 25 2012
property ref T front(T)(T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[])) { assert(a.length, "Attempting to fetch the front of an empty array of " ~ typeof(a[0]).stringof); return a[0]; } Why is front returned by ref even when it is not possible to do so?
Jun 25 2012
On 06/25/2012 04:27 PM, Roman D. Boiko wrote:property ref T front(T)(T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[])) { assert(a.length, "Attempting to fetch the front of an empty array of " ~ typeof(a[0]).stringof); return a[0]; } Why is front returned by ref even when it is not possible to do so?It should always be possible to do so. What you are experiencing seems to be a compiler bug.
Jun 25 2012
On Monday, 25 June 2012 at 15:38:09 UTC, Timon Gehr wrote:It should always be possible to do so. What you are experiencing seems to be a compiler bug.I couldn't find it reported before. The closest are: d.puremagic.com/issues/show_bug.cgi?id=6480 http://d.puremagic.com/issues/show_bug.cgi?id=7258 I guess I should report it?
Jun 25 2012
On Monday, 25 June 2012 at 15:58:14 UTC, Roman D. Boiko wrote:On Monday, 25 June 2012 at 15:38:09 UTC, Timon Gehr wrote:http://d.puremagic.com/issues/show_bug.cgi?id=8297It should always be possible to do so. What you are experiencing seems to be a compiler bug.I couldn't find it reported before. The closest are: http://d.puremagic.com/issues/show_bug.cgi?id=6480 http://d.puremagic.com/issues/show_bug.cgi?id=7258 I guess I should report it?
Jun 25 2012
On Monday, June 25, 2012 16:27:20 Roman D. Boiko wrote:property ref T front(T)(T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[])) { assert(a.length, "Attempting to fetch the front of an empty array of " ~ typeof(a[0]).stringof); return a[0]; } Why is front returned by ref even when it is not possible to do so?What do you mean that it's not possible? What's not possible about it? - Jonathan M Davis
Jun 25 2012
On Monday, 25 June 2012 at 15:39:07 UTC, Jonathan M Davis wrote:On Monday, June 25, 2012 16:27:20 Roman D. Boiko wrote:Looks like I came to wrong conclusions, so my statement from second post should be ignored. The first post shows the problem.property ref T front(T)(T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[])) { assert(a.length, "Attempting to fetch the front of an empty array of " ~ typeof(a[0]).stringof); return a[0]; } Why is front returned by ref even when it is not possible to do so?What do you mean that it's not possible? What's not possible about it? - Jonathan M Davis
Jun 25 2012
On Monday, 25 June 2012 at 14:23:25 UTC, Roman D. Boiko wrote:import std.range; struct Element { //immutable // uncomment to break compilation int _i; this(int i) { _i = i; } } void main() { auto arr = [Element.init]; arr.front; } Declaring _i immutable yields the following compilation error: /usr/include/x86_64-linux-gnu/dmd/phobos/std/array.d(460): Error: a[0LU] isn't mutable sample.d(11): Error: template instance std.array.front!(Element) error instantiating Is this a bug, or I misunderstand something?This is a bug of the compiler, and it is already filed. http://d.puremagic.com/issues/show_bug.cgi?id=6336 I've already posted a pull request to fix the bug, but it has been hold a while. Kenji Hara
Jun 25 2012