该InputRange概念具有三个功能,例如:
struct InputRange(T) {
@property bool empty();
@property T front();
void popFront();
}简而言之,一种
检查范围是否为空
获取当前元素
移至下一个元素
要使自己的类型为a InputRange,我们必须实现这三个功能。让我们看一下正方形的无限序列。
struct SquaresRange {
int cur = 1;
@property bool empty() {
return false;
}
@property int front() {
return cur^^2;
}
void popFront() {
cur++;
}
}有关斐波那契的示例,请参见D导览。