Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-01

How to implement an iif with generic?

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hello,

I'm tried all options in
http://wiki.freepascal.org/Generics_proposals. But, without success. :(

In the last test:

function Max<T>(A, B: T): T;
begin
  if A < B then
    Result := B
  else
    Result := A;
end;
The error is: unit1.pas(30,13) Fatal: Syntax error, ":" expected but "<" found.

What is the syntax for implementing a generic function? I'm trying to implement an faster iif function.

Thanks,

Silvio Cl?cio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email

Paul Ishenin
to silvioprog

26.01.2012 10:13, silvioprog ?????:

Show quoted text 14 lines
In the last test: function Max<T>(A, B: T): T; begin if A< B then Result := B else Result := A; end; The error is: unit1.pas(30,13) Fatal: Syntax error, ":" expected but "<" found. What is the syntax for implementing a generic function? I'm trying to implement an faster iif function.

This is not yet implemented in the compiler.

Best regards,
Paul Ishenin.

Reply by email

silvioprog
to Paul Ishenin

2012/1/26 Paul Ishenin :

Show quoted text 22 lines
26.01.2012 10:13, silvioprog ?????: > In the last test: > > function Max<T>(A, B: T): T; > begin > ? if A< ?B then > ? ? Result := B > ? else > ? ? Result := A; > end; > > The error is: unit1.pas(30,13) Fatal: Syntax error, ":" expected but "<" > found. > > What is the syntax for implementing a generic function? I'm trying to > implement an faster iif function. This is not yet implemented in the compiler. Best regards, Paul Ishenin.

Thanks.

Silvio Cl?cio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email