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