d切片示例

原文

struct Integers {
  private int z = 0;

  public bool empty() { return false; }

  public int front() { return this.z; }

  public void popFront()
  {
    this.z *= -1;
    if (this.z <= 0)
      --this.z;
  }
}

void main()
{
  import std.stdio : writeln;

  foreach (const z; Integers()) {
    writeln(z);
    if (z == 5)
      break;
  }
}
posted @ 2022-08-08 09:09  zjh6  阅读(13)  评论(0)    收藏  举报  来源