3 ms·
To provide a simple example of how comptime is used for generics in Zig, consider the ArrayList. Idiomatic Zig code uses TitleCase for types, but ArrayList is t
by AnIdiotOnTheNet 5y ago
To provide a simple example of how comptime is used for generics in Zig, consider the ArrayList. Idiomatic Zig code uses TitleCase for types, but ArrayList is technically a function with the signature `ArrayList(comptime T: type) type`. Given the type `T` as an argument, it returns a new type `ArrayList(T)` that implements the ArrayList for `T`. You can initialize a new ArrayList of `Foo`s like this: `var list = ArrayList(Foo).init(allocator);`.
No second macro language, no magic variables, no special syntax.