pub fn firstTrue(vec: anytype) ?VectorIndex(@TypeOf(vec)) vec304
305
306
307
308
309
310
311
312
313
314pub fn firstTrue(vec: anytype) ?VectorIndex(@TypeOf(vec)) {
const len = vectorLength(@TypeOf(vec));
const IndexInt = VectorIndex(@TypeOf(vec));
if (!@reduce(.Or, vec)) {
return null;
}
const all_max: @Vector(len, IndexInt) = @splat(~@as(IndexInt, 0));
const indices = @select(IndexInt, vec, iota(IndexInt, len), all_max);
return @reduce(.Min, indices);
}