[Issue 7924] reduce does not work with immutable/const as map and filter do
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 19 20:17:04 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=7924
irritate <irritate at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |irritate at gmail.com
--- Comment #1 from irritate <irritate at gmail.com> 2013-06-19 20:17:02 PDT ---
The error message on head revision (DMD 2.064) is different, but this still
fails to compile. The problem here is that reduce() fails to instantiate
because of an isIterable constraint check on the immutable iota.
I "unwound" the example into just the iteration:
---
import std.stdio ;
void main()
{
immutable r = iota(0, 10);
foreach(elem; r)
{
writeln(elem);
}
}
DMD v2.064 DEBUG
issue_7924.d(8): Error: mutable method std.range.iota!(int,
int).iota.Result.popFront is not callable using a immutable object
---
And popFront mutates a member variable for the current value, so I don't think
there's much we can do about this.
SIDE NOTE: map and filter work because they Unqual the iota when they wrap it.
However they also have non-const popFront, and making them immutable directly
also leads to issues because of that:
---
import std.stdio ;
void main()
{
immutable r = map!(i => i*i)(iota(0, 10));
foreach(elem; r)
{
writeln(elem);
}
}
DMD v2.064 DEBUG
issue_7924.d(7): Error: cannot implicitly convert expression (map(iota(0, 10))
of type MapResult!(__lambda2, Result) to immutable(MapResult!(__lambda2,
Result)
)
---
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list