[fpc-pascal] Feature announcement: implicit generic function specializations

Martin Frb lazarus at mfriebe.de
Mon Apr 25 09:39:18 CEST 2022


On 25/04/22 05:15, Hairy Pixels via fpc-pascal wrote:
> generic function Add<T>(left, right: T): T;
>
> And the programmer intends to call it like:
>
> 	Add(1,1);
>
>
> Why should the programmer need to tell the compiler it’s dealing with Integer when it’s so obvious from the types being used?

Actually, it's dealing with SmallInt (or ShortInt). And if the 
programmer does not know that, then it might be an issue...

Imagine the generic code (something more complex than "Add") would 
somehow do something that differs for SmallInt and Integer. Like using 
"SizeOf(T)".

Sure it can be solved by explicit specialization "Add<Integer>(1,1)".
But to solve it that way, the programmer needs to know... And he might 
not...



More information about the fpc-pascal mailing list