| Section | Title |
|---|---|
| 1 | What Is comptime |
| 2 | Compile-Time Variables |
| 3 | Inline Branching |
| 4 | Compile-Time Loops |
| 5 | Generating Code at Compile Time |
| 6 | Reflection with @typeInfo |
| 7 | Building Generic Data Structures |
| 8 | Static Dispatch |
| 9 | Metaprogramming Patterns |
| 10 | When Not to Use comptime |
What Is `comptime`comptime means “compile time.”
Compile-Time VariablesIn the previous section, you learned that Zig can execute code during compilation.
Inline BranchingInline branching means Zig chooses a branch during compilation, not during runtime.
Compile-Time LoopsA compile-time loop is a loop that runs while Zig is compiling your program.
Generating Code at Compile TimeGenerating code at compile time means using Zig code to create specialized program behavior before the final executable is built.
Reflection with `@typeInfo`Reflection means inspecting a type as data.
Building Generic Data StructuresA generic data structure is a data structure that works with more than one element type.
Static DispatchStatic dispatch means the compiler decides which code to call before the program runs.
Metaprogramming PatternsMetaprogramming means writing code that helps create, inspect, or specialize other code.
When Not to Use `comptime`comptime is one of Zig’s strongest features, but it should not be used everywhere.