Typed indexes in Zig

34 points by lvig


tomekw

So it's like Ada's:

type Column is range 0 .. Max_Column;
type Row_Index is range 0 .. Max_Row;

but ~35 years later?

mgriffin

I frequently find myself wishing for languages/standard-libraries to build-in the ability to say "this array is indexed by that integral (new-)type". You can build it yourself, but because the syntax is heavier at definition and use sites I often don't.

Admittedly, I do a lot of low-level performance-y work. If you're not worried about performance then your language's Map type is usually a way to get that type safety.