| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn isArrayOf(comptime T: type) fn (type) bool { |
| 6 | const Closure = struct { |
| 7 | pub fn trait(comptime C: type) bool { |
| 8 | return switch (@typeInfo(C)) { |
| 9 | .array => |ti| ti.child == T, |
| 10 | else => false, |
| 11 | }; |
| 12 | } |
| 13 | }; |
| 14 | return Closure.trait; |
| 15 | } |
| 16 | |
| 17 | const L = isArrayOf(u8); |
| 18 | test { |
| 19 | try std.testing.expect(L([5]u8)); |
| 20 | } |
| 21 | test { |
| 22 | try std.testing.expect(!L([3]u32)); |
| 23 | } |
| 24 | test { |
| 25 | try std.testing.expect(!L(struct { a: u8 })); |
| 26 | } |
| 27 | test { |
| 28 | try std.testing.expect(!L(enum { a, b, c })); |
| 29 | } |