#Can zig generate more code at comptime?

1 messages · Page 1 of 1 (latest)

jaunty grove
#

Since zig has a very powerful comptime, would it be possible to for example generate 100 different functions at comptime? Would I be able to generate code in general?

finite sinew
#

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"?

jaunty grove
#

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.

steady crystal
steady crystal
# jaunty grove 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

jaunty grove
#

That is very impressive