// TODO perhaps we should put these under the count, int, int8, etc. namespaces? namespace range { typedef type = (int current, int end, int step); alias type here(int current, int end, int step) { return (current, end, step); } alias bool type:next_element(var type^ r, var int^ result) { if r^.step > 0 and r^.current > r^.end return :false; if r^.step < 0 and r^.current < r^.end return :false; result^ = r^.current; r^.current += r^.step; return :true; } } namespace indexrange { typedef type = (count current, count length); alias type here(count length) { return (0, length); } alias bool type:next_element(var type^ r, var count^ result) { if r^.current >= r^.length return :false; result^ = r^.current; r^.current += 1; return :true; } } namespace revindexrange { typedef type = (count current); alias type here(count length) { return (length,); } alias bool type:next_element(var type^ r, var count^ result) { if r^.current == 0 return :false; r^.current -= 1; result^ = r^.current; return :true; } }