| ... | ... | @@ -2367,7 +2367,7 @@ test "iterate over an array" { |
| 2367 | 2367 | var some_integers: [100]i32 = undefined; |
| 2368 | 2368 | |
| 2369 | 2369 | test "modify an array" { |
| 2370 | | for (some_integers) |*item, i| { |
| 2370 | for (&some_integers, 0..) |*item, i| { |
| 2371 | 2371 | item.* = @intCast(i32, i); |
| 2372 | 2372 | } |
| 2373 | 2373 | try expect(some_integers[10] == 10); |
| ... | ... | @@ -2408,7 +2408,7 @@ comptime { |
| 2408 | 2408 | // use compile-time code to initialize an array |
| 2409 | 2409 | var fancy_array = init: { |
| 2410 | 2410 | var initial_value: [10]Point = undefined; |
| 2411 | | for (initial_value) |*pt, i| { |
| 2411 | for (&initial_value, 0..) |*pt, i| { |
| 2412 | 2412 | pt.* = Point{ |
| 2413 | 2413 | .x = @intCast(i32, i), |
| 2414 | 2414 | .y = @intCast(i32, i) * 2, |
| ... | ... | @@ -2461,8 +2461,8 @@ test "multidimensional arrays" { |
| 2461 | 2461 | try expect(mat4x4[1][1] == 1.0); |
| 2462 | 2462 | |
| 2463 | 2463 | // Here we iterate with for loops. |
| 2464 | | for (mat4x4) |row, row_index| { |
| 2465 | | for (row) |cell, column_index| { |
| 2464 | for (mat4x4, 0..) |row, row_index| { |
| 2465 | for (row, 0..) |cell, column_index| { |
| 2466 | 2466 | if (row_index == column_index) { |
| 2467 | 2467 | try expect(cell == 1.0); |
| 2468 | 2468 | } |
| ... | ... | @@ -3579,7 +3579,7 @@ test "tuple" { |
| 3579 | 3579 | } ++ .{false} ** 2; |
| 3580 | 3580 | try expect(values[0] == 1234); |
| 3581 | 3581 | try expect(values[4] == false); |
| 3582 | | inline for (values) |v, i| { |
| 3582 | inline for (values, 0..) |v, i| { |
| 3583 | 3583 | if (i != 2) continue; |
| 3584 | 3584 | try expect(v); |
| 3585 | 3585 | } |
| ... | ... | @@ -4659,10 +4659,10 @@ test "for basics" { |
| 4659 | 4659 | } |
| 4660 | 4660 | try expect(sum == 20); |
| 4661 | 4661 | |
| 4662 | | // To access the index of iteration, specify a second capture value. |
| 4663 | | // This is zero-indexed. |
| 4662 | // To access the index of iteration, specify a second condition as well |
| 4663 | // as a second capture value. |
| 4664 | 4664 | var sum2: i32 = 0; |
| 4665 | | for (items) |_, i| { |
| 4665 | for (items, 0..) |_, i| { |
| 4666 | 4666 | try expect(@TypeOf(i) == usize); |
| 4667 | 4667 | sum2 += @intCast(i32, i); |
| 4668 | 4668 | } |
| ... | ... | @@ -4674,7 +4674,7 @@ test "for reference" { |
| 4674 | 4674 | |
| 4675 | 4675 | // Iterate over the slice by reference by |
| 4676 | 4676 | // specifying that the capture value is a pointer. |
| 4677 | | for (items) |*value| { |
| 4677 | for (&items) |*value| { |
| 4678 | 4678 | value.* += 1; |
| 4679 | 4679 | } |
| 4680 | 4680 | |
| ... | ... | @@ -5659,7 +5659,7 @@ fn genFoos(allocator: Allocator, num: usize) ![]Foo { |
| 5659 | 5659 | var foos = try allocator.alloc(Foo, num); |
| 5660 | 5660 | errdefer allocator.free(foos); |
| 5661 | 5661 | |
| 5662 | | for(foos) |*foo, i| { |
| 5662 | for (foos, 0..) |*foo, i| { |
| 5663 | 5663 | foo.data = try allocator.create(u32); |
| 5664 | 5664 | // This errdefer does not last between iterations |
| 5665 | 5665 | errdefer allocator.destroy(foo.data); |
| ... | ... | @@ -5700,14 +5700,14 @@ fn genFoos(allocator: Allocator, num: usize) ![]Foo { |
| 5700 | 5700 | // Used to track how many foos have been initialized |
| 5701 | 5701 | // (including their data being allocated) |
| 5702 | 5702 | var num_allocated: usize = 0; |
| 5703 | | errdefer for(foos[0..num_allocated]) |foo| { |
| 5703 | errdefer for (foos[0..num_allocated]) |foo| { |
| 5704 | 5704 | allocator.destroy(foo.data); |
| 5705 | 5705 | }; |
| 5706 | | for(foos) |*foo, i| { |
| 5706 | for (foos, 0..) |*foo, i| { |
| 5707 | 5707 | foo.data = try allocator.create(u32); |
| 5708 | 5708 | num_allocated += 1; |
| 5709 | 5709 | |
| 5710 | | if(i >= 3) return error.TooManyFoos; |
| 5710 | if (i >= 3) return error.TooManyFoos; |
| 5711 | 5711 | |
| 5712 | 5712 | foo.data.* = try getData(); |
| 5713 | 5713 | } |
| ... | ... | @@ -7265,7 +7265,7 @@ const Writer = struct { |
| 7265 | 7265 | comptime var state = State.start; |
| 7266 | 7266 | comptime var next_arg: usize = 0; |
| 7267 | 7267 | |
| 7268 | | inline for (format) |c, i| { |
| 7268 | inline for (format, 0..) |c, i| { |
| 7269 | 7269 | switch (state) { |
| 7270 | 7270 | State.start => switch (c) { |
| 7271 | 7271 | '{' => { |
| ... | ... | @@ -8629,7 +8629,7 @@ test "integer cast panic" { |
| 8629 | 8629 | This function is a low level intrinsic with no safety mechanisms. Most code |
| 8630 | 8630 | should not use this function, instead using something like this: |
| 8631 | 8631 | </p> |
| 8632 | | <pre>{#syntax#}for (source[0..byte_count]) |b, i| dest[i] = b;{#endsyntax#}</pre> |
| 8632 | <pre>{#syntax#}for (dest, source[0..byte_count]) |*d, s| d.* = s;{#endsyntax#}</pre> |
| 8633 | 8633 | <p> |
| 8634 | 8634 | The optimizer is intelligent enough to turn the above snippet into a memcpy. |
| 8635 | 8635 | </p> |
| ... | ... | @@ -11116,7 +11116,7 @@ pub fn main() !void { |
| 11116 | 11116 | const args = try std.process.argsAlloc(gpa); |
| 11117 | 11117 | defer std.process.argsFree(gpa, args); |
| 11118 | 11118 | |
| 11119 | | for (args) |arg, i| { |
| 11119 | for (args, 0..) |arg, i| { |
| 11120 | 11120 | std.debug.print("{}: {s}\n", .{ i, arg }); |
| 11121 | 11121 | } |
| 11122 | 11122 | } |
| ... | ... | @@ -11142,7 +11142,7 @@ pub fn main() !void { |
| 11142 | 11142 | |
| 11143 | 11143 | const preopens = try fs.wasi.preopensAlloc(arena); |
| 11144 | 11144 | |
| 11145 | | for (preopens.names) |preopen, i| { |
| 11145 | for (preopens.names, 0..) |preopen, i| { |
| 11146 | 11146 | std.debug.print("{}: {s}\n", .{ i, preopen }); |
| 11147 | 11147 | } |
| 11148 | 11148 | } |