std.range should support recursion (Was: One-line FFT, nice!)

Mehrdad wfunction at hotmail.com
Tue Sep 25 08:42:28 PDT 2012


On Tuesday, 25 September 2012 at 13:34:28 UTC, Andrei 
Alexandrescu wrote:
> On 9/25/12 4:23 AM, Mehrdad wrote:
>> On Tuesday, 25 September 2012 at 08:21:39 UTC, Mehrdad wrote:
>>> without creating new times
>>
>>
>> new types**
>
> Ah, better now. Still it would be great to explain it more :o).
>
> Andrei

Haha ok. :) I mean like, essentially, these need to work:

assert(is(typeof(foo.stride(1)) == 
typeof(foo.stride(2).stride(3))));
assert(is(typeof(foo.drop(1)) == typeof(foo.drop(2).drop(3))));
assert(is(typeof(foo.take(1)) == typeof(foo.take(2).take(3))));

otherwise recursion with these ranges is impossible.

The FFT example took the odd- and even-indexed numbers with 
stride(), but it couldn't recursively do this because the type 
system prevented it from doing so.

So I was forced to copy the array unnecessarily every time.

Also, foo should be implicitly convertible to 
typeof(foo.stride(1)), which also makes recursion easier.


More information about the Digitalmars-d mailing list