unit ugenerictest;
{$MODE objfpc}{$H+}
{$MODESWITCH AdvancedRecords}
{$IFDEF FPC}
{$PACKRECORDS C}
{$ENDIF}
{$INLINE ON}
interface
type
generic TGGenericPoint<T> = packed record
public
x, y : T;
procedure flip; inline;
procedure invert; inline;
function longest: T;
function shortest: T;
function divXY: T;
end;
implementation
procedure TGGenericPoint.flip;
var a: T;
begin
a := x;
x := y;
y := a;
end;
procedure TGGenericPoint.invert;
begin
x := -x;
y := -y;
end;
function TGGenericPoint.longest: T;
begin
if x >= y
then Result := x
else Result := y;
end;
function TGGenericPoint.shortest: T;
begin
if x <= y
then Result := x
else Result := y;
end;
function TGGenericPoint.divXY: T;
begin
Result := x / y; // <--- how can the compiler determine if we are dealing with integer or float?
end;