From d10e407977f1ba165ca3d0a04d7b270096185559 Mon Sep 17 00:00:00 2001 From: data-man Date: Tue, 26 May 2020 15:52:37 +0500 Subject: [PATCH] More vector support in std.meta --- lib/std/meta.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/std/meta.zig b/lib/std/meta.zig index e38712af2b..68426323b2 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -102,9 +102,10 @@ test "std.meta.alignment" { pub fn Child(comptime T: type) type { return switch (@typeInfo(T)) { .Array => |info| info.child, + .Vector => |info| info.child, .Pointer => |info| info.child, .Optional => |info| info.child, - else => @compileError("Expected pointer, optional, or array type, found '" ++ @typeName(T) ++ "'"), + else => @compileError("Expected pointer, optional, array or vector type, found '" ++ @typeName(T) ++ "'"), }; } @@ -113,22 +114,25 @@ test "std.meta.Child" { testing.expect(Child(*u8) == u8); testing.expect(Child([]u8) == u8); testing.expect(Child(?u8) == u8); + testing.expect(Child(Vector(2, u8)) == u8); } /// Given a "memory span" type, returns the "element type". pub fn Elem(comptime T: type) type { switch (@typeInfo(T)) { - .Array => |info| return info.child, + .Array, => |info| return info.child, + .Vector, => |info| return info.child, .Pointer => |info| switch (info.size) { .One => switch (@typeInfo(info.child)) { .Array => |array_info| return array_info.child, + .Vector => |vector_info| return vector_info.child, else => {}, }, .Many, .C, .Slice => return info.child, }, else => {}, } - @compileError("Expected pointer, slice, or array, found '" ++ @typeName(T) ++ "'"); + @compileError("Expected pointer, slice, array or vector type, found '" ++ @typeName(T) ++ "'"); } test "std.meta.Elem" { @@ -136,6 +140,8 @@ test "std.meta.Elem" { testing.expect(Elem([*]u8) == u8); testing.expect(Elem([]u8) == u8); testing.expect(Elem(*[10]u8) == u8); + testing.expect(Elem(Vector(2, u8)) == u8); + testing.expect(Elem(*Vector(2, u8)) == u8); } /// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value,