No index for cycle ranges

Andrej Mitrovic none at none.none
Thu Jun 2 11:17:26 PDT 2011


import std.range;

void main()
{
    auto arr = [1, 2, 3, 4, 5, 6, 7, 8];
    auto foo = cycle(arr);
    
    // nope
    foreach (int index, int val; foo)
    {
    }    
    
    // nope
    foreach (int index, int val; take(foo, 5))
    {
    }
    
    // ok
    foreach (int index, int val; take(arr, 5))
    {
    }    
}

Is this because cycle is an infinite range, and index might overflow? I could understand that. But I think if I use take() then there should be no problem with overflows. It still doesn't work though.


More information about the Digitalmars-d-learn mailing list