Generics feature status

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Generics feature status

leledumbo
Administrator
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?
Reply | Threaded
Open this post in threaded view
|

Re: Generics feature status

Anthony Walter-3
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;

On Fri, Apr 29, 2011 at 3:28 PM, leledumbo <[hidden email]> wrote:
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 archive at Nabble.com.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Generics feature status

Paul Ishenin-2
In reply to this post by leledumbo
30.04.2011 3:28, leledumbo wrote:
> 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?--
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Generics feature status

Sven Barth-2
On 30.04.2011 03:15, Paul Ishenin wrote:

> 30.04.2011 3:28, leledumbo wrote:
>> 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?--
> 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.

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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal