1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
/*
* $Id: iterator.d,v 1.2 2005/01/01 12:40:28 kenta Exp $
*
* Copyright 2004 Kenta Cho. Some rights reserved.
*/
module abagames.util.iterator;
/**
* Simple iterator for array.
*/
public class ArrayIterator(T) {
protected:
T[] array;
int idx;
private:
public this(T[] a) {
array = a;
idx = 0;
}
public bool hasNext() {
if (idx >= array.length)
return false;
else
return true;
}
public T next() {
if (idx >= array.length)
throw new Error("No more items");
T result = array[idx];
idx++;
return result;
}
}
alias ArrayIterator!(string) StringIterator;
|