From Asbjørn, 7 Years ago, written in Delphi (Object Pascal).
Embed
  1. uses
  2.   System.SysUtils;
  3.  
  4. type
  5.   Func<T, R> = reference to function(const Arg: T): R;
  6.  
  7. type
  8.   Alg = record
  9.     class procedure Exec<T, R>(const f: Func<T, R>); overload; static;
  10.   end;
  11.  
  12. { Alg }
  13.  
  14. class procedure Alg.Exec<T, R>(const f: Func<T, R>);
  15. begin
  16.  
  17. end;
  18.  
  19. type
  20.   TRec = record
  21.     x: integer;
  22.   end;
  23.  
  24.   TRecHelper = record helper for TRec
  25.     function ToString: string; overload; inline;
  26.     class function ToString(const Value: TRec): string; overload; inline; static;
  27.   end;
  28.  
  29. { TRecHelper }
  30.  
  31. function TRecHelper.ToString: string;
  32. begin
  33.  
  34. end;
  35.  
  36. class function TRecHelper.ToString(const Value: TRec): string;
  37. begin
  38.  
  39. end;
  40.  
  41. begin
  42.   Alg.Exec<integer, string>(integer.ToString); // Works in D10, barfs in D10.1
  43.   Alg.Exec<TRec, string>(TRec.ToString); // Barfs in either
  44. end.
  45.