ElementType!(Range) problem
Ishan Thilina
ishanthilina at gmail.com
Wed Apr 6 01:57:45 PDT 2011
--Philippe wrote::
>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;
>
Got it!. Thanks.
I faced this confusion because of the description for "ElementType" which is
available in http://d-programming-language.org/phobos/std_range.html. It says,
"
template ElementType(R):
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 or type R. For example,
ElementType!(T[]) is T. If R is not a range, ElementType!R is void.
"
So I thought that just passing ElementType!listR was adequate. :s
More information about the Digitalmars-d-learn
mailing list