Advertisement
Guest User

Untitled

a guest
Nov 9th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. test "generic gt" {
  2. const local = struct {
  3. fn gt(x: anytype, y: anytype) bool {
  4. return x > y;
  5. }
  6. fn gt_mono(x: u8, y: u8) bool {
  7. return x > y;
  8. }
  9. fn check5_3(comptime f: fn (anytype, anytype) bool) bool {
  10. return f(@as(u8, 5), 3);
  11. }
  12. fn check5_3_explicit(comptime T: type, f: fn (T, T) bool) bool {
  13. return f(@as(T, 5), 3);
  14. }
  15. fn check5_3_mono(f: fn (u8, u8) bool) bool {
  16. // not allowed: return check5_3(5, 3);
  17. return check5_3_explicit(u8, f);
  18. }
  19. };
  20. expect(local.gt(@as(u8, 5), 3));
  21. expect(local.gt(5, @as(f32, 3)));
  22. expect(local.check5_3(local.gt));
  23. expect(local.check5_3_mono(local.gt_mono));
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement