I am writing a function in Zig that should accept multidimensional arrays of arbitrary sizes. There can be limits but I am unable to hardcode the sizes in advance.
Here is an example:
const warn = @import("std").debug.warn;
fn printMap(map: []const [4]bool) void {
for (map) |row| {
for (row) |tile| {
warn("{}\t", .{tile});
}
warn("\n", .{});
}
}
pub fn main() !void {
const map = [_][4]bool{
[_]bool{ false, false, false, false },
[_]bool{ false, true, true, false },
[_]bool{ false, true, true, false },
[_]bool{ false, false, false, false },
};
printMap(map[0..]);
}
This compiles and runs but if I change the function signature to
fn printMap(map: []const []bool) void
I receive the error
expected type '[]const []bool', found '[]const [4]bool'
Is this possible to express in Zig?