| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | const indexOfAggregate = extras.indexOfAggregate; |
| 5 | |
| 6 | pub fn containsAggregate(comptime T: type, haystack: []const T, needle: T) bool { |
| 7 | return indexOfAggregate(T, haystack, needle) != null; |
| 8 | } |
| 9 | |
| 10 | test { |
| 11 | const S = struct { |
| 12 | a: u8, |
| 13 | |
| 14 | fn eql(this: @This(), other: @This()) bool { |
| 15 | return this.a == other.a; |
| 16 | } |
| 17 | }; |
| 18 | const data = [_]S{ |
| 19 | .{ .a = 8 }, |
| 20 | .{ .a = 6 }, |
| 21 | .{ .a = 7 }, |
| 22 | .{ .a = 2 }, |
| 23 | .{ .a = 4 }, |
| 24 | .{ .a = 1 }, |
| 25 | .{ .a = 9 }, |
| 26 | .{ .a = 3 }, |
| 27 | .{ .a = 5 }, |
| 28 | }; |
| 29 | try std.testing.expect(containsAggregate(S, &data, .{ .a = 4 })); |
| 30 | try std.testing.expect(!containsAggregate(S, &data, .{ .a = 0 })); |
| 31 | } |