| author | |
| committer | |
| log | feae209ba5cbc9b92a240f2e8e531c1b913bef3f |
| tree | 72da6def6790e451f1255d1f0a726dbee6261042 |
| parent | 285c8f82b4d32760005a1167e0f78c16f8230d06 |
| signature | Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw |
3 files changed, 18 insertions(+), 3 deletions(-)
src/isIndexable.zig+1-3| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const extras = @import("./lib.zig"); |
| 4 | const isTuple = extras.isTuple; | |
| 4 | 5 | |
| 5 | 6 | pub fn isIndexable(comptime T: type) bool { |
| 6 | 7 | if (comptime is(.pointer)(T)) { |
| ... | ... | @@ -19,9 +20,6 @@ fn is(comptime id: std.builtin.TypeId) fn (type) bool { |
| 19 | 20 | }; |
| 20 | 21 | return Closure.trait; |
| 21 | 22 | } |
| 22 | fn isTuple(comptime T: type) bool { | |
| 23 | return is(.@"struct")(T) and @typeInfo(T).@"struct".is_tuple; | |
| 24 | } | |
| 25 | 23 | |
| 26 | 24 | test { |
| 27 | 25 | const array = [_]u8{0} ** 10; |
src/isTuple.zig created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | ||
| 5 | pub fn isTuple(comptime T: type) bool { | |
| 6 | return is(.@"struct")(T) and @typeInfo(T).@"struct".is_tuple; | |
| 7 | } | |
| 8 | fn is(comptime id: std.builtin.TypeId) fn (type) bool { | |
| 9 | const Closure = struct { | |
| 10 | pub fn trait(comptime T: type) bool { | |
| 11 | return id == @typeInfo(T); | |
| 12 | } | |
| 13 | }; | |
| 14 | return Closure.trait; | |
| 15 | } |
src/lib.zig+2| ... | ... | @@ -89,6 +89,7 @@ pub const compareFnSlice = @import("./compareFnSlice.zig").compareFnSlice; |
| 89 | 89 | pub const sumLen = @import("./sumLen.zig").sumLen; |
| 90 | 90 | pub const splitScalarN = @import("./splitScalarN.zig").splitScalarN; |
| 91 | 91 | pub const indexOfAggregate = @import("./indexOfAggregate.zig").indexOfAggregate; |
| 92 | pub const isTuple = @import("./isTuple.zig").isTuple; | |
| 92 | 93 | |
| 93 | 94 | test { |
| 94 | 95 | _ = @import("reduceNumber.zig"); |
| ... | ... | @@ -167,4 +168,5 @@ test { |
| 167 | 168 | _ = @import("sumLen.zig"); |
| 168 | 169 | _ = @import("splitScalarN.zig"); |
| 169 | 170 | _ = @import("indexOfAggregate.zig"); |
| 171 | _ = @import("isTuple.zig"); | |
| 170 | 172 | } |