4 ms·
It is very easy to specialise a function in zig, you just put if(T == u8) or something like that inside the function and do w/e in there
by ozgrakkurt 1y ago
It is very easy to specialise a function in zig, you just put if(T == u8) or something like that inside the function and do w/e in there
- unwind 1y agoCan the compiler detect that and use the proper code so no test is needed at runtime? This is Zig so I guess the answer is "yeah, duh" but wanted to ask since it sounded like the solution is less, uh, "compiler-friendly" than I would expect.
- hansvm 1y agoYes, and if you're paranoid you can write if (comptime T == u8) { // code } to guarantee that if you're wrong about how the compiler behaves then you'll get a compiler error.
- dpatterbee 1y agoZig has no type info at runtime so this is and always will be guaranteed to be a comptime check.
- Zambyte 1y agoHence the paranoia :-D But I do think adding explicit `comptime` in places like this is reasonable for the sake of conveying intent to other programmers.