[fpc-pascal] Feature announcement: Generic functions, procedures and methods

Anthony Walter sysrpl at gmail.com
Mon Nov 23 01:30:47 CET 2015


More ...

// This works

function TestIsAs2<T: TObject>(Item: TObject): T;
begin
  if Item is T then
  begin
    Exit(Item as T);
  end;
  Result := nil;
end;

Now before you say "of course" :) I find it interesting because is and as
are operators, just like > greater than and < less than are operators. In
previous examples no constraints were needed to use operators.

Having said that, I am find with being forced to use a constraint with "as"
and "is", because they are operators which cannot be overloaded.

Good work!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20151122/40e72664/attachment.html>


More information about the fpc-pascal mailing list