std.array.array extended example to supplement that in std.array
Steve Teale
steve.teale at britseyeview.com
Sun Feb 7 04:01:01 PST 2010
import std.array;
import std.range;
import std.stdio;
// A contrived input range
struct Sir
{
string s;
int pos;
bool empty() { return pos >= s.length; }
void popFront() { pos++; }
int front() { return s[pos]-'0'; }
}
int[] da = [1,2,3,4,5];
int[5] sa = [1,2,3,4,5];
void main()
{
auto a1 = array(da); // dynamic array
writefln("[%s]", a1);
auto a2 = array(sa[]); // slice (all) of static array
writefln("[%s]", a2);
auto a3 = array([1,2,3,4,5][]); // ditto
writefln("[%s]", a3);
Sir sir;
sir.s = "12345";
assert(isInputRange!(Sir));
auto a4 = array(sir);
writefln("[%s]", a4);
}
More information about the Digitalmars-d-learn
mailing list