| ... | @@ -102,9 +102,10 @@ test "std.meta.alignment" { | ... | @@ -102,9 +102,10 @@ test "std.meta.alignment" { |
| 102 | pub fn Child(comptime T: type) type { | 102 | pub fn Child(comptime T: type) type { |
| 103 | return switch (@typeInfo(T)) { | 103 | return switch (@typeInfo(T)) { |
| 104 | .Array => |info| info.child, | 104 | .Array => |info| info.child, |
| | 105 | .Vector => |info| info.child, |
| 105 | .Pointer => |info| info.child, | 106 | .Pointer => |info| info.child, |
| 106 | .Optional => |info| info.child, | 107 | .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) ++ "'"), |
| 108 | }; | 109 | }; |
| 109 | } | 110 | } |
| 110 | | 111 | |
| ... | @@ -113,22 +114,25 @@ test "std.meta.Child" { | ... | @@ -113,22 +114,25 @@ test "std.meta.Child" { |
| 113 | testing.expect(Child(*u8) == u8); | 114 | testing.expect(Child(*u8) == u8); |
| 114 | testing.expect(Child([]u8) == u8); | 115 | testing.expect(Child([]u8) == u8); |
| 115 | testing.expect(Child(?u8) == u8); | 116 | testing.expect(Child(?u8) == u8); |
| | 117 | testing.expect(Child(Vector(2, u8)) == u8); |
| 116 | } | 118 | } |
| 117 | | 119 | |
| 118 | /// Given a "memory span" type, returns the "element type". | 120 | /// Given a "memory span" type, returns the "element type". |
| 119 | pub fn Elem(comptime T: type) type { | 121 | pub fn Elem(comptime T: type) type { |
| 120 | switch (@typeInfo(T)) { | 122 | switch (@typeInfo(T)) { |
| 121 | .Array => |info| return info.child, | 123 | .Array, => |info| return info.child, |
| | 124 | .Vector, => |info| return info.child, |
| 122 | .Pointer => |info| switch (info.size) { | 125 | .Pointer => |info| switch (info.size) { |
| 123 | .One => switch (@typeInfo(info.child)) { | 126 | .One => switch (@typeInfo(info.child)) { |
| 124 | .Array => |array_info| return array_info.child, | 127 | .Array => |array_info| return array_info.child, |
| | 128 | .Vector => |vector_info| return vector_info.child, |
| 125 | else => {}, | 129 | else => {}, |
| 126 | }, | 130 | }, |
| 127 | .Many, .C, .Slice => return info.child, | 131 | .Many, .C, .Slice => return info.child, |
| 128 | }, | 132 | }, |
| 129 | else => {}, | 133 | else => {}, |
| 130 | } | 134 | } |
| 131 | @compileError("Expected pointer, slice, or array, found '" ++ @typeName(T) ++ "'"); | 135 | @compileError("Expected pointer, slice, array or vector type, found '" ++ @typeName(T) ++ "'"); |
| 132 | } | 136 | } |
| 133 | | 137 | |
| 134 | test "std.meta.Elem" { | 138 | test "std.meta.Elem" { |
| ... | @@ -136,6 +140,8 @@ test "std.meta.Elem" { | ... | @@ -136,6 +140,8 @@ test "std.meta.Elem" { |
| 136 | testing.expect(Elem([*]u8) == u8); | 140 | testing.expect(Elem([*]u8) == u8); |
| 137 | testing.expect(Elem([]u8) == u8); | 141 | testing.expect(Elem([]u8) == u8); |
| 138 | testing.expect(Elem(*[10]u8) == u8); | 142 | testing.expect(Elem(*[10]u8) == u8); |
| | 143 | testing.expect(Elem(Vector(2, u8)) == u8); |
| | 144 | testing.expect(Elem(*Vector(2, u8)) == u8); |
| 139 | } | 145 | } |
| 140 | | 146 | |
| 141 | /// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value, | 147 | /// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value, |