I am trying to get something similar to a C++ std::vector<std::vector<type>> and having some issues. Below is a minimally reproducible example of how I am trying to use ArrayList. The code compiles and runs, but no numbers get printed out. What is the proper way to have a type similar to std::vector<std::vector<>> in Zig. Any guidance on my misunderstanding of ArrayList is much appreciated. Thanks.
const std = @import("std");
pub fn main() !void {
var gps = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gps.allocator();
var array = std.ArrayList(std.ArrayList(usize)).init(allocator);
for (0..10) |_| {
try array.append(std.ArrayList(usize).init(allocator));
var tmp = array.getLast();
for (0..10) |j| {
try tmp.append(j);
}
}
for (array.items) |row| {
std.debug.print("row: ", .{});
for (row.items) |col| {
std.debug.print(" {d}", .{col});
}
std.debug.print("\n", .{});
}
}