1 import std.range : iota; 2 3 // Standard arrays: returns the type of the elements of the array 4 static assert(is(ElementType!(int[]) == int)); 5 6 // Accessing .front retrieves the decoded dchar 7 static assert(is(ElementType!(char[]) == dchar)); // rvalue 8 static assert(is(ElementType!(dchar[]) == dchar)); // lvalue 9 10 // Ditto 11 static assert(is(ElementType!(string) == dchar)); 12 static assert(is(ElementType!(dstring) == immutable(dchar))); 13 14 // For ranges it gets the type of .front. 15 auto range = iota(0, 10); 16 static assert(is(ElementType!(typeof(range)) == int));
The element type of R. R does not have to be a range. The element type is determined as the type yielded by r.front for an object r of type R. For example, ElementType!(T[]) is T if T[] isn't a narrow string; if it is, the element type is dchar. If R doesn't have front, ElementType!R is void.