[fpc-pascal] Procedural parameters

Sven Barth pascaldragon at googlemail.com
Sun Dec 15 17:19:40 CET 2024


Am 15.12.2024 um 13:11 schrieb Hairy Pixels via fpc-pascal:
> On Dec 15, 2024 at 6:28:25 PM, Hairy Pixels <genericptr at gmail.com> wrote:
>> Also noteworthy is ISO standard can accommodate generics which 
>> Borland’s design can not. 
>
> Wait, I’m wrong on this, you can use generic proc types. The problem 
> with generics are pointers to T.  For example that below is not possible.
>
> type
>   generic TFindNodeComparator<T> = function(item: ^T): Boolean;
>
> generic function FindNode<T>(func: specialize TFindNodeComparator<T>): ^T;

It's not as if it is impossible to workaround this limitation:

=== code begin ===

program tpointerrec;

{$mode objfpc}
{$modeswitch advancedrecords}

type
   generic TPointer<T> = record
   type
     PT = ^T;
   end;

   generic TFindNodeComparator<T> = function(item: specialize 
TPointer<T>.PT): Boolean;

generic function FindNode<T>(func: specialize TFindNodeComparator<T>): 
specialize TPointer<T>.PT;
begin
end;

function Compare(item: specialize TPointer<LongInt>.PT): Boolean;
begin
end;

begin
   specialize FindNode<LongInt>(@Compare);
end.

=== code end ===

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20241215/734dc013/attachment-0001.htm>


More information about the fpc-pascal mailing list