is array an InputRange?

Piotr Szturmaj bncrbme at jadamspam.pl
Fri Oct 5 06:46:53 PDT 2012


ref2401 wrote:
> import std.range;
>
> int[] numbers = [1, 3, 5, 7, 9, 11];
>
> auto rangeObject = inputRangeObject(numbers);
> auto inputRange = cast(InputRange!(int[]))rangeObject;
>
> why does 'inputRange' equal null?

Because you specified int[] element type and cast operator returns null 
when objects don't implement requested interface. You need to specify 
int as element type:

auto inputRange = cast(InputRange!int)rangeObject;

Anyway you don't need to cast to InputRange(E) interface. You can use 
rangeObject directly.


More information about the Digitalmars-d-learn mailing list