Generic swap: Difference between revisions

Content added Content deleted
Line 271:
 
=={{header|Delphi}}==
{{incorrect|Delphi|Option 1 demonstrates a dubious arithmetic trick for swapping integers that works on two's complement hardware thanks to wrapping behavior of arithmetic overflow. Neither option demonstrates generic programming: swapping two variables using the same function or operator, regardless of their type.}}
 
Option 1:
<lang Delphi>
procedure Swap<T>(var a, b: IntegerT);
begin
a := a + b;
b := a - b;
a := a - b;
end;
</lang>
Option 2:
<lang Delphi>
procedure Swap(var a, b: Integer);
var
temp: IntegerT;
begin
temp := a;