[fpc-pascal] procedure that accept generic types?
Xiangrong Fang
xrfang at gmail.com
Wed Sep 4 09:13:44 CEST 2013
Thanks. This is sort-of too verbose when use. I have no comments about
how to define it, but when use it, can we just use:
ProcessArray(someintarray); ?
The complier should be able to "specialize" it implicitly because it knows
someintarray is array of integer?
alternatively, how about this:
var
proc_ints: specialize ProcessArray<LongInt>;
begin
proc_ints(someintarray);
end;
use it without explicit specialize is best, however.
2013/9/4 Sven Barth <pascaldragon at googlemail.com>
> Am 04.09.2013 08:18, schrieb Xiangrong Fang:
>
> Hi There,
>
> I try to write a procedure with generic parameters, but failed:
>
> type
> generic TArray<T> = array of T;
>
> procedure ProcessArray(arr: TArray<T>);
> begin
> end;
>
>
> The compiler said "Generics without specialization cannot be used..."
>
> But if I specialize the parameter then this procedure is useless.
>
> Any ideas?
>
> This is not yet supported. A proof of concept implementation exists
> locally on my computer however. It will then look like this:
>
> === code begin ===
>
>
> type
> generic TArray<T> = array of T;
>
> generic procedure ProcessArray<T>(arr: TArray<T>);
> begin
> end;
>
> begin
> // usage:
> specialize ProcessArray<LongInt>(someintarray);
> end.
>
> === code end ===
>
> Regards,
> Sven
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130904/0722203a/attachment.html>
More information about the fpc-pascal
mailing list