I see now that generics have improved a lot since latest release, we even have Delphi compatible syntax in Delphi mode. Recursive generic type is supported as well now (finally, I can continue my data structure library :)). Seeing these facts, what's the status of this feature now? Is it considered stable?--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Generics-feature-status-tp4359580p4359580.html Sent from the Free Pascal - General mailing list .
Mailing lists / fpc-pascal / 2011-04
Generics feature status
4 messages · 4 people · –
- AAnthony Walter 1
- Lleledumbo 1
- PPaul Ishenin 1
- SSven Barth 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Is this true? I'd really like to see generics that with a mode where it is possible to say with the following syntax (compatible with Delphi):
type
IDelegate<T> = interface
procedure Add(const Handler: T);
procedure Remove(const Handler: T);
end;And then specialize using the following syntax:
type
INotifyDelegate = IDelegate<TNotifyEvent>;Also, generic constraints are needed:
type
TComponentTool<T: TComponent> = class(TObject)
public
procedure DoSomething(const C: T);
end;leledumbo wrote 12 lines
I see now that generics have improved a lot since latest release, we even have Delphi…
leledumbo wrote 5 lines
No, they are not stable. FPC generic syntax may change. But you can rely on delphi syntax (as we can't change it) with few limitations at the moment:
- no multiply generics with the same identifier and different amount of type parameters [1],
- no generic methods,
- no type constraints.
Also I may forgot something.
About [1] - in delphi it is possible to define different generics with the same identifier and different amount of type parameteres (even in the same unit). E.g.
TList = class ...; TList<T> = class ...; TList<T, TT> = class ...;
Then you can declare variables with any of that types. E.g.
var
L: TList;
LI: TList<Integer>;
LIO: TList<Integer,TObject>As I know Sven will work to support this and other missing generics features.
Best regards,
Paul Ishenin
Paul Ishenin wrote 29 lines
Point 1 is already on a good way - with backwards compatible FPC syntax :) The only thing that still scares me are those nasty inline declarations -.-
Type constraints (at least non-interface ones) should be rather easy to do. The hardest part might be the parsing.
Regarding generic methods: I've already found the points where I'll need to hook in and keep those in mind while extending/adjusting the existing code, but that's it currently.
Regards,
Sven
