4 ms·
I personally find returning a type from a comptime function to be quite elegant. Template parameters and regular parameters are unified into a single concept.
by haberman 3y ago
I personally find returning a type from a comptime function to be quite elegant. Template parameters and regular parameters are unified into a single concept.
Zig's comptime is analogous to constinit, because it lets you compute a value at compile time and ensure that it is linker-initialized into the final binary image.
The point about CTRP is interesting, I'd have to think about that some more.
- Conscat 3y agoI would consider that similar to a `inline constexpr` variable rather than a `constinit` variable. A `constinit` variable calls a constexpr constructor, but doesn't produce a constant. EDIT: Oh, I think I see how it's like `constinit`. If you have a non-`comptime` variable that is initialized by a `comptime` function, then it's a non-constant constant-initialized variable.