struct Foo
{
Range opSlice() { return Range(); }
static struct Range
{
int front() { return 10; }
void popFront() { counter++; }
bool empty() { return counter >= 10; }
private:
import std.array;
int counter;
}
private:
int bar;
}
void main(string[] args)
{
import std.stdio;
import std.array;
Foo foo;
auto x = foo[].array();
writeln(x);
}
The above example fails to compile. If you remove the "import std.array;" line from the Range struct, this works as intended. It also works if you write "auto x = array(foo[]);"
Comment #1 by monarchdodra — 2014-04-25T06:03:31Z
Strange. I had thought it had something to do with "array" name collision. But the situation is the same with, say "replicate":
auto x = foo[].replicate(5); //FAIL
auto x = replicate(foo[], 5); //OK
In any case, here is a somewhat simplified test case. We don't need nested structs to trigger it:
//----
struct Range
{
import std.array;
int front() @property { return 10; }
void popFront() { counter++; }
bool empty() @property { return counter >= 10; }
private:
int counter;
}
void main(string[] args)
{
import std.stdio;
import std.array;
Range r;
auto x1 = array(r);
auto x2 = r.array();
writeln(x);
}
//----
Comment #2 by johannes.loher — 2018-05-05T11:51:23Z
I tested this on diefferent compiler versions. It seems to work correctly since 2.071.2.