Hello together!

Just a little feature teaser what I'm currently working on when I find the time. :)

=== source begin ===

program tgenfuncs;

{$modeswitch result}

generic function IsIn<T>(aElement: T; const aArray: array of T): Boolean;
var
  elem: T;
begin
  for elem in aArray do
    if elem = aElement then
      Exit(True);
  Result := False;
end;

begin
  Writeln(specialize IsIn<LongInt>(42, [21, 42, 84]));
  Writeln(specialize IsIn<LongInt>(5, [21, 42, 84]));
  Writeln(specialize IsIn<String>('Foobar', ['Foo', 'Bar', 'Blubber']));
end.

=== source end ===

=== console begin ===

PS D:\svn\fpc> .\compiler\i386\pp.exe -n -Furtl\units\i386-win32 -FEtestoutput -viwn .\fpctests\tgenfuncs.pas
Target OS: Win32 for i386
Compiling .\fpctests\tgenfuncs.pas
Linking testoutput\tgenfuncs.exe
19 lines compiled, 0.3 sec, 32224 bytes code, 1204 bytes data
PS D:\svn\fpc> .\testoutput\tgenfuncs.exe
TRUE
FALSE
FALSE

=== console end ===

Regards,
Sven
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to