Re:Zig Performance Tracking Dashboard
by AnIdiotOnTheNet on Monday December 06, 2021 @01:11PM
(#29463427)
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.
No second macro language, no magic variables, no special syntax.