auto r1 = [0, 1, 2, 3, 4, 5]; auto s = segment!2(r1); assert(equal(s, [tuple(0, 1), tuple(1, 2), tuple(2, 3), tuple(3, 4), tuple(4, 5)][])); assert(s.length == 5); // .length // back/popBack: assert(equal(retro(s), retro([tuple(0, 1), tuple(1, 2), tuple(2, 3), tuple(3, 4), tuple(4, 5)][]))); assert(s[3] == tuple(3, 4)); // opIndex s[3] = tuple(0, 0); // opIndexAssign not ref opIndex assert(s[2] == tuple(2, 0)); // it affects its neighbors. assert(s[4] == tuple(0, 5)); assert(r1 == [0, 1, 2, 0, 0, 5][]); // affects r1 back (no .dup internally) auto st = ["a","b","c","d","e","f"]; auto s2 = segment!3(st); assert(s2.front == tuple("a","b","c")); auto r1 = [0,1,2,3,4,5]; // regenerates r1 auto s3 = segment!1(r1); assert(equal(s3, [tuple(0), tuple(1), tuple(2), tuple(3), tuple(4), tuple(5)][])); auto r2 = map!"a*a"(r1); auto s4 = segment!2(r2); // On a forward range assert(equal(s4, [tuple(0,1), tuple(1,4), tuple(4,9), tuple(9,16), tuple(16,25)][])); int[] e; auto s5 = segment!2(e); assert(s5.empty);
あるレンジのN個の連続する要素のリストを返します。