On Nov 25, 2025 at 9:55:46 PM, Martin Frb via fpc-devel <
[email protected]> wrote:
> Thanks, which just for confirmation brings up a follow up question. (I
> haven't used generic function much yet, so maybe I miss something)
>
> function Foo (aParam: Integer): integer;
> generic function Foo<T>(aParam: t) : integer;
>
>
> Those are 2 different function too? (not an overload? because "T" could be
> integer in same cases)
>
> Do you then always have to call the generic using
> specialize Foo<integer>(1)
> ?
>
> I seem to remember a discussion about adding automatic specialization?
> But then
> foo('abc') // would be clear, to specialize with string
> but
> foo(1) // could be either
> _______________________________________________
>
yes those are two different functions. The generic function is just a
template which includes the parsed tokens and is named with $X where X is
the number of generic parameters. Only at the time of specialization is the
code generated, until the it's just an array of tokens.
there is a {$modeswitch implicitfunctionspecialization} mode switch ( my
work so I apologize for the bugs 😂) which infers the parameter type so
that foo('abc') becomes foo<String>('String').
_______________________________________________
fpc-devel maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel