#Can zig generate more code at comptime?
1 messages · Page 1 of 1 (latest)
If you use generic types, it will create a copy of the function for each type you give it. Could you give more detail on what you mean by "generate code"?
Just curious, could I for example go ahead and in an inlined for loop create 100 functions that simply return the current index. This would of course not ever be needed, but I am more so trying to see how far I could push the compiler.
inline for (0..100) |i| {
const func = struct {
fn f() usize {
return i;
}
}.f;
}
That is very cool
pretty much "generating a generic function" involves capturing some comptime value, so if a value is known at comptime you can use it to generate a function for it
That is very impressive