On Wed, 20 Apr 2022 19:15:15 +0200 Sven Barth via fpc-pascal <[email protected]> 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 _______________________________________________ fpc-pascal maillist - [email protected] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
