| ... | ... | @@ -102,9 +102,10 @@ test "std.meta.alignment" { |
| 102 | 102 | pub fn Child(comptime T: type) type { |
| 103 | 103 | return switch (@typeInfo(T)) { |
| 104 | 104 | .Array => |info| info.child, |
| 105 | .Vector => |info| info.child, |
| 105 | 106 | .Pointer => |info| info.child, |
| 106 | 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 | 114 | testing.expect(Child(*u8) == u8); |
| 114 | 115 | testing.expect(Child([]u8) == u8); |
| 115 | 116 | testing.expect(Child(?u8) == u8); |
| 117 | testing.expect(Child(Vector(2, u8)) == u8); |
| 116 | 118 | } |
| 117 | 119 | |
| 118 | 120 | /// Given a "memory span" type, returns the "element type". |
| 119 | 121 | pub fn Elem(comptime T: type) type { |
| 120 | 122 | switch (@typeInfo(T)) { |
| 121 | | .Array => |info| return info.child, |
| 123 | .Array, => |info| return info.child, |
| 124 | .Vector, => |info| return info.child, |
| 122 | 125 | .Pointer => |info| switch (info.size) { |
| 123 | 126 | .One => switch (@typeInfo(info.child)) { |
| 124 | 127 | .Array => |array_info| return array_info.child, |
| 128 | .Vector => |vector_info| return vector_info.child, |
| 125 | 129 | else => {}, |
| 126 | 130 | }, |
| 127 | 131 | .Many, .C, .Slice => return info.child, |
| 128 | 132 | }, |
| 129 | 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 | 138 | test "std.meta.Elem" { |
| ... | ... | @@ -136,6 +140,8 @@ test "std.meta.Elem" { |
| 136 | 140 | testing.expect(Elem([*]u8) == u8); |
| 137 | 141 | testing.expect(Elem([]u8) == u8); |
| 138 | 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 | 147 | /// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value, |