Working with ranges: mismatched function return type inference

drug via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 11 09:01:09 PDT 2016


11.10.2016 18:46, orip пишет:
> On Tuesday, 11 October 2016 at 13:06:37 UTC, pineapple wrote:
>> Rewrite `return chain(ints[0..5], ints[8..$]);` as `return ints[0..5]
>> ~ ints[8..$];`
>>
>> The `chain` function doesn't return an array, it returns a
>> lazily-evaluated sequence of an entirely different type from `int[]`.
>
> Of course it does! I would like the function to return an "input range
> of int", no matter which one specifically. Is this possible?
it doesn't. Using runtime argument you can't choose compile time 
parameter - returned type. So it's impossible. Almost - b/c you can use 
Algebraic. Again you can do the following:

```D
return chain(ints[0..5], ints[8..$]).array; // it returns int[]
```


More information about the Digitalmars-d-learn mailing list