authorgravatar for datamanrb@gmail.comdata-man <datamanrb@gmail.com> 2020-05-25 01:50:22+05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-24 20:44:17-04:00
logb13dd3cf61fc01b189b5b585651f46de9319953e
treeb57a7af9eaaad4d471fd548897878df26d214895
parentdd05f2be80464deb8c98adb9b621364838c17f2b

Treat vectors as indexable


1 files changed, 3 insertions(+), 1 deletions(-)

lib/std/meta/trait.zig+3-1
...@@ -273,17 +273,19 @@ pub fn isIndexable(comptime T: type) bool {...@@ -273,17 +273,19 @@ pub fn isIndexable(comptime T: type) bool {
273 }273 }
274 return true;274 return true;
275 }275 }
276 return comptime is(.Array)(T);276 return comptime is(.Array)(T) or is(.Vector)(T);
277}277}
278278
279test "std.meta.trait.isIndexable" {279test "std.meta.trait.isIndexable" {
280 const array = [_]u8{0} ** 10;280 const array = [_]u8{0} ** 10;
281 const slice = @as([]const u8, &array);281 const slice = @as([]const u8, &array);
282 const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;
282283
283 testing.expect(isIndexable(@TypeOf(array)));284 testing.expect(isIndexable(@TypeOf(array)));
284 testing.expect(isIndexable(@TypeOf(&array)));285 testing.expect(isIndexable(@TypeOf(&array)));
285 testing.expect(isIndexable(@TypeOf(slice)));286 testing.expect(isIndexable(@TypeOf(slice)));
286 testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));287 testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
288 testing.expect(isIndexable(@TypeOf(vector)));
287}289}
288290
289pub fn isNumber(comptime T: type) bool {291pub fn isNumber(comptime T: type) bool {