> If you want to pass a pointer to ^T in a generic function is there anyway
> safe to do this currently? Pascal doesn’t allow ^ types in function arguments
> (why?) and generics don’t seems to support pointers either (why?).
>
> generic TValues<T> = array[0..0] of T;
> generic PValues<T> = ^specialize TValues<T>;
>
> I guess the only thing to do is use a untyped pointer and cast it to the
> correct type inside the function declaration?
>
> For example here is a generic QuickSort function which operates on any array
> of T.
>
> type
> generic TComparator<T> = function (left: T; right: T; context: pointer):
> integer;
>
> generic procedure QuickSort<T>(_values: pointer; first, last: LongInt;
> comparator: specialize TComparator<T>);
> type
> TValues = array[0..0] of T;
> PValues = ^TValues;
> var
> pivot,j,i: integer;
> temp: T;
> values: PValues absolute _values;
>
> Regards,
> Ryan Joseph
>
Not that pretty, but I use something like:
==============================================
generic TPtr<T> = record
public
type P = ^T;
public
ptr: P;
end;
generic function Ref<T>(out r: specialize TPtr<T>.P):boolean;
==============================================
Denis Golovan
_______________________________________________
fpc-pascal maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal