{$MODE OBJFPC}
{$LONGSTRINGS ON}
{$APPTYPE CONSOLE}
type
generic TDoStd<_T> = class
public
class function DoIt(a: _T): _T; static;
end;
function MyFun(const a: Double): Double;
begin
Result := a + 1.0;
end;
function MyFun(const a: string): string;
begin
Result := a + 'Hi all';
end;
class function TDoStd.DoIt(a: _T): _T; static;
begin
if TypeInfo(_T) = TypeInfo(Double) then
Double(Result) := MyFun(Double(a))
else
if TypeInfo(_T) = TypeInfo(string) then
string(Result) := MyFun(string(a))
else
Result := Default(_T);
end;
type
TDoItDouble = specialize TDoStd<double>;
TDoItString = specialize TDoStd<string>;
begin
Writeln(TDoItDouble.DoIt(0.2):0:2);
Writeln(TDoItString.DoIt('Well, '));
Readln;
end.