Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test "generic gt" {
- const local = struct {
- fn gt(x: anytype, y: anytype) bool {
- return x > y;
- }
- fn gt_mono(x: u8, y: u8) bool {
- return x > y;
- }
- fn check5_3(comptime f: fn (anytype, anytype) bool) bool {
- return f(@as(u8, 5), 3);
- }
- fn check5_3_explicit(comptime T: type, f: fn (T, T) bool) bool {
- return f(@as(T, 5), 3);
- }
- fn check5_3_mono(f: fn (u8, u8) bool) bool {
- // not allowed: return check5_3(5, 3);
- return check5_3_explicit(u8, f);
- }
- };
- expect(local.gt(@as(u8, 5), 3));
- expect(local.gt(5, @as(f32, 3)));
- expect(local.check5_3(local.gt));
- expect(local.check5_3_mono(local.gt_mono));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement