Creating switch cases programmatically

You want inline else, which turns a runtime value into a comptime known value by duplicated the switch statements.

Eg,

return switch (tag) {
  inline else => |t| comptime some_condition(t),
}

I would also say the inline for over the allowed flags is a good solution for this specific case. The optimizer should be able to equally optimize such a simple chain of ifs as it could a switch.

5 Likes