authorgravatar for datamanrb@gmail.comdata-man <datamanrb@gmail.com> 2020-05-26 15:52:37+05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-26 10:56:29-04:00
logd10e407977f1ba165ca3d0a04d7b270096185559
treea89b8c94075357e3c657728a6649efa81d6ca4f0
parent4b8077ea8e888382fc73dd8a19c6e9160f2cef46

More vector support in std.meta


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

lib/std/meta.zig+9-3
......@@ -102,9 +102,10 @@ test "std.meta.alignment" {
102102pub fn Child(comptime T: type) type {
103103 return switch (@typeInfo(T)) {
104104 .Array => |info| info.child,
105 .Vector => |info| info.child,
105106 .Pointer => |info| info.child,
106107 .Optional => |info| info.child,
107 else => @compileError("Expected pointer, optional, or array type, found '" ++ @typeName(T) ++ "'"),
108 else => @compileError("Expected pointer, optional, array or vector type, found '" ++ @typeName(T) ++ "'"),
108109 };
109110}
110111
......@@ -113,22 +114,25 @@ test "std.meta.Child" {
113114 testing.expect(Child(*u8) == u8);
114115 testing.expect(Child([]u8) == u8);
115116 testing.expect(Child(?u8) == u8);
117 testing.expect(Child(Vector(2, u8)) == u8);
116118}
117119
118120/// Given a "memory span" type, returns the "element type".
119121pub fn Elem(comptime T: type) type {
120122 switch (@typeInfo(T)) {
121 .Array => |info| return info.child,
123 .Array, => |info| return info.child,
124 .Vector, => |info| return info.child,
122125 .Pointer => |info| switch (info.size) {
123126 .One => switch (@typeInfo(info.child)) {
124127 .Array => |array_info| return array_info.child,
128 .Vector => |vector_info| return vector_info.child,
125129 else => {},
126130 },
127131 .Many, .C, .Slice => return info.child,
128132 },
129133 else => {},
130134 }
131 @compileError("Expected pointer, slice, or array, found '" ++ @typeName(T) ++ "'");
135 @compileError("Expected pointer, slice, array or vector type, found '" ++ @typeName(T) ++ "'");
132136}
133137
134138test "std.meta.Elem" {
......@@ -136,6 +140,8 @@ test "std.meta.Elem" {
136140 testing.expect(Elem([*]u8) == u8);
137141 testing.expect(Elem([]u8) == u8);
138142 testing.expect(Elem(*[10]u8) == u8);
143 testing.expect(Elem(Vector(2, u8)) == u8);
144 testing.expect(Elem(*Vector(2, u8)) == u8);
139145}
140146
141147/// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value,