[fpc-pascal] Feature announcement: implicit generic function specializations
    Hairy Pixels 
    genericptr at gmail.com
       
    Fri Apr 22 04:11:34 CEST 2022
    
    
  
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
    
    
More information about the fpc-pascal
mailing list