| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn isSlice(comptime T: type) bool { |
| 6 | if (comptime is(.Pointer)(T)) { |
| 7 | return @typeInfo(T).Pointer.size == .Slice; |
| 8 | } |
| 9 | return false; |
| 10 | } |
| 11 | fn is(comptime id: std.builtin.TypeId) fn (type) bool { |
| 12 | const Closure = struct { |
| 13 | pub fn trait(comptime T: type) bool { |
| 14 | return id == @typeInfo(T); |
| 15 | } |
| 16 | }; |
| 17 | return Closure.trait; |
| 18 | } |
| 19 | |
| 20 | test { |
| 21 | const array = [_]u8{0} ** 10; |
| 22 | var runtime_zero: usize = 0; |
| 23 | _ = &runtime_zero; |
| 24 | try std.testing.expect(isSlice(@TypeOf(array[runtime_zero..]))); |
| 25 | try std.testing.expect(!isSlice(@TypeOf(array))); |
| 26 | try std.testing.expect(!isSlice(@TypeOf(&array[0]))); |
| 27 | } |