Hi,
I'm trying to write a generic linked-list without the use of classes and objects.
I need to be able to create generic pointer like this:
Type
generic PGList<T> = ^specialize TGList<T>;
Mailing lists / fpc-pascal / 2016-11
6 messages · 2 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
I'm trying to write a generic linked-list without the use of classes and objects.
I need to be able to create generic pointer like this:
Type
generic PGList<T> = ^specialize TGList<T>;Here is the complete snippet that i wanted to create
Type
generic PGList<T> = ^specialize TGList<T>;
generic TGList<T> = record
data: T;
next: specialize PGList<T>
end;You'll need to use nested types (they require modeswitch advancedrecords), like this:
=== code begin ===
type
generic TGList<T> = record
public type
TSelf = specialize TGList<T>;
PGList = ^TSelf;
public
data: T;
next: PGList;
end;=== code end ===
Note: the TSelf construct is currently needed due to a bug in the compiler.
Regards,
Sven
Is there any entry on Mantis for me to keep track of this bug status?
Thanks.
"Le Duc Hieu" wroteIs there any entry on Mantis for me to keep track of this bug status?
No, because I just noticed that there is one when testing for your question ;)
Regards,
Sven
Is there any entry on Mantis for me to keep track of this bug status? Thanks. On Sun, Nov…
Le Duc Hieu wroteIs there any entry on Mantis for me to keep track of this bug status?
I've fixed that bug now (it did already work in mode Delphi by the way), so now you can use this:
=== code begin ===
type
generic TGList<T> = record
public type
PGList = ^specialize TGList<T>;
public
data: T;
next: PGList<T>;
end;{ or even }
generic TGList<T> = record
data: T;
next: ^specialize TGList<T>;
end;=== code end ===
Please note that the specialization must always be *inside* the record and the top one needs modeswitch advancedrecords due to the type section.
Regards,
Sven