1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub 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
14test {
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}