| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn lessThanBy(comptime T: type, comptime field: std.meta.FieldEnum(T)) fn (void, T, T) bool { |
| 6 | const S = struct { |
| 7 | pub fn lessThan(_: void, lhs: T, rhs: T) bool { |
| 8 | return @field(lhs, @tagName(field)) < @field(rhs, @tagName(field)); |
| 9 | } |
| 10 | }; |
| 11 | return S.lessThan; |
| 12 | } |
| 13 | |
| 14 | test { |
| 15 | const S = struct { x: u32 }; |
| 16 | const l = lessThanBy(S, .x); |
| 17 | try std.testing.expect(l({}, .{ .x = 19 }, .{ .x = 53 })); |
| 18 | try std.testing.expect(!l({}, .{ .x = 44 }, .{ .x = 44 })); |
| 19 | try std.testing.expect(!l({}, .{ .x = 89 }, .{ .x = 26 })); |
| 20 | } |