Zig 0.12.0: comptime meta-programming feels natural

Posted by Ghatotkacha Veer · 2024-02-24

Zig 0.12 ships comptime improvements that make meta-programming feel natural. New build system and package manager are finally usable. The systems language for people who think Rust is too complex. https://github.com/ziglang/zig/releases/tag/0.12.0

// Zig 0.12 comptime meta-programming
fn Matrix(comptime T: type, comptime rows: usize, comptime cols: usize) type {
    return struct {
        data: [rows][cols]T,

        const Self = @This();
        pub fn zero() Self {
            return .{ .data = .{.{0} ** cols} ** rows };
        }
    };
}

const Mat4 = Matrix(f32, 4, 4);
var m = Mat4.zero();

Explore GitVibes