2 ms·
You aren't returning the new type there, looks like you just inline that code. Zig lets you create and return new types that way while your example looks like j
by Jensson 4y ago
You aren't returning the new type there, looks like you just inline that code. Zig lets you create and return new types that way while your example looks like just regular template substitution.
Edit: So the main difference seems to be that types are first class citizens in Zig, you can write a normal comptime function that returns a type and either use it to do more metaprogramming or everywhere you would declare a type for a function or variable. I am not aware of any static typed languages that lets you do this with normal language syntax.
C++ does it with templates, but in Zig you can do what C++ templates can but with if statements and loops.
- pjmlp 4y agoJust use the Circle compiler and you have the full C++ language at compile time, available today.
- WalterBright 4y agoIt is returning a new type. Please show me an example where it differs. D's metaprogramming is very good at constructing types. A member of the D community tried very hard to implement type functions, but it turned out to be redundant with D's existing capability.