[fpc-pascal] How to use generics and meta class?
Joao Morais
l at joaomorais.com.br
Fri Feb 28 12:05:40 CET 2014
Em 28/02/14 03:44, Sven Barth escreveu:
>
> === code end ===
>
> Currently this will print:
>
> === output begin ===
>
> Bar
>
> === output end ===
>
> If the compiler would now naively generate an implementation of
> TMyGeneric with TMyType then the result would be:
>
> === output begin ===
>
> Foo
>
> === output end ===
>
> This must not be. So the compiler - while it might generate an
> implicit TMyType implementation - must not use that implicit
> implemenation if the type that is specialized with implements non
> virtual methods itself. This is one of the restrictions.
Ah, now I see. "TGeneric<T: TType>" is quite different from "var T:
TType". Afaics the former is a placeholder for another type, the latter
is a placeholder for an implementation. Thanks for sharing.
>>> Addendum: this does not exclude the compiler from trying to optimize
>>> this if the type parameter is indeed a class type. But this will be
>>> transparent for the user and will have a few restrictions. It does
>>> however not change that generics aren't full types.
>>
>> :/
>>
>> Maybe in the near (or not so near) future, these two approaches
>> (templates and generics like in Java) may live together? I mean: is this
>> technically possible?
>
> FPC/Delphi generics are more templates than generics. Generics are not
> full types. This will not change.
Got the point. Anyway current (2.6) generics meets about 80% of my needs
and 2.8 sounds to meet about 98% =). Thanks for the really great work
with generics!
More information about the fpc-pascal
mailing list