On 7/2/2011 10:22 PM, Jonathan M Davis wrote:
On 2011-07-02 18:14, Johann MacDonagh wrote:
On 7/2/2011 9:00 PM, Johann MacDonagh wrote:
On 7/2/2011 9:00 PM, bearophile wrote:
Johann MacDonagh:
I'm confused, what am I doing wrong here?
I think that Phobos needs way more&better unittests.
I think the error you receive reduces to this:
import std.range: isForwardRange;
void foo(R)(R r) if (isForwardRange!R) {}
void main() {
immutable arr = [1, 2];
foo(arr);
}
Bye,
bearophile
Strangely enough there is a unit test for this...
https://github.com/D-Programming-Language/phobos/blob/phobos-2.053/std/al
gorithm.d#L6742
Does this code fail to compile for you too? I want to make sure I didn't
mess up my config here.
Ah, here we go:
http://d.puremagic.com/issues/show_bug.cgi?id=6148
Replacing immutable with auto works. I'm still confused how the phobos
unit tests pass though...
That's because they're using immutable(int)[], not immutable int[]. The
elements in the range are immutable, but the range is not. Whereas with
immutable int[], the whole thing is immutable, so it doesn't work. The range
has to be mutable.
- Jonathan M Davis
Ah! How could I miss that? Some of the examples in std.algorithm should
be updated to reflect this at least until that bug is fixed.