Compile-Time Evaluation
- comptime. comptime runs Zig at compile time: the same language, executed while building.
- comptime parameters. A comptime parameter must be compile-time known: types and configuration as arguments.
- Compile-time asserts. comptime asserts check invariants at build: wrong configurations refusing to compile.
Generic Programming
- Types as values. Types are values at comptime: fn List(comptime T: type) type returns a new struct.
- Duck-typed generics. Generic code checks per instantiation: capabilities verified where used, errors at the call site.
- std as the example. The standard library IS the generics textbook: ArrayList and HashMap built from comptime.
Compile-Time Code Generation
- Inline for. inline for unrolls over fields and types at compile time: reflection without a runtime.
- @typeInfo. @typeInfo inspects types as data: serialisers and validators generated from struct shapes.
- Restraint. comptime power is budgeted: readable instantiations over clever meta-towers.
Before and after this level
- Before: Level 5: Errors & Optionals: Error Unions, Optionals, Explicit Failure Handling.
- Next: Level 7: Modules & Build System: Modules, Zig Build, Dependencies and Cross Compilation.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Zig Level 6: Comptime cover?
Compile-Time Evaluation, Generic Programming, Compile-Time Code Generation: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 5: Errors & Optionals, which covers Error Unions, Optionals, Explicit Failure Handling.