Function iota [src]
Returns a vector containing the first len integers in order from 0 to len-1.
For example, iota(i32, 8) will return a vector containing .{0, 1, 2, 3, 4, 5, 6, 7}.
Prototype
pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T)
Parameters
T: type
len: usize
Source
pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) {
comptime {
var out: [len]T = undefined;
for (&out, 0..) |*element, i| {
element.* = switch (@typeInfo(T)) {
.int => @as(T, @intCast(i)),
.float => @as(T, @floatFromInt(i)),
else => @compileError("Can't use type " ++ @typeName(T) ++ " in iota."),
};
}
return @as(@Vector(len, T), out);
}
}