> > I get a "untitled.d(32): Error: template instance ElementType!(listR) does not > match template declaration ElementType(R)" error. > > What could be the problem ? > -------------------------------------------------------------------------- > > import std.stdio; > import std.range; > import std.container; > > int main(char[][] args) > { > auto list=SList!(int)(1,2,3); > auto listR=list.opSlice(); > writefln("%s",ElementType!(listR)); > > > return 0; > } > --------------------------------------------------------------
ElementType acts on types. It takes a type and 'returns' (compiles to, actually) another type. You need to give it typeof(listR). Then, as ElementType!(typeof(listR)) is a type, you cannot pass it to writeln. Use .stringof to go from the type to a string representation of its name. So: writefln("%s", ElementType!(typeof(listR)).stringof); ElementType!(typeof(listR)) is a type like any other. You can create a variable with it: ElementType!(typeof(listR)) elem; Btw, .opSlice() is the name of the '[]' operator. You previous line can be written like this: auto listR = list[]; Philippe