[fpc-pascal] Feature announcement: implicit generic function specializations
Mattias Gaertner
nc-gaertnma at netcologne.de
Wed Apr 20 22:48:24 CEST 2022
On Wed, 20 Apr 2022 19:15:15 +0200
Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>[...]
> This feature is enabled with the modeswitch
> ImplicitFunctionSpecialization and is for now not enabled by default
> as this has the potential to break existing code.
Sad. This feature really makes generic functions shine.
>[...]
> generic function ArrayFunc<T>(aArg: specialize TArray<T>): T;
>[...]
> type
> generic TTest<T> = function(aArg: T): T;
>
> generic function Apply<T>(aFunc: specialize TTest<T>; aArg: T): T;
>[...]
> begin
> Writeln(ArrayFunc([1, 2, 3])); // will write 6
> Writeln(ArrayFunc(['Hello', 'FPC', 'World'])); // will write
> HelloFPCWorld
>
> Writeln(Apply(@StrFunc, 'Foobar')); // will write FOOBAR
> Writeln(Apply(@NegFunc, 42)); // will write -42
> end.
Mind boggling. :)
Mattias
More information about the fpc-pascal
mailing list