
What Is Zig's Comptime? - mpweiher
https://kristoff.it/blog/what-is-zig-comptime/
======
komuW
quite clever and pretty powerful, you can even use it to come up with generic
constraints/concepts/contracts in userland without language support. Something
along the lines of:

    
    
        // A generic Max function that only works for Float & Ints
        fn Max(comptime T: type, a: T, b: T) T {
            switch (@typeInfo(T)) {
                .Float => {}, // all floats are ok
                .Int => {}, // all ints are ok
                else => {
                    @compileError("Max not allowed for type: " ++ @typeName(T));
                },
            }
    
            return if (a > b) a else b;
        }

