<=>
') OperatorAddition of a swap operator with the suggested symbol '<=>
'.
Jeff Walker (language designer)
Experts to Contact: Status: Being ConsideredSwapping two values is a common action which requires several lines of code. These obscure the intent of the programmer. Without by reference arguments it is not possible to write a swap function.
Description:The swap operator ('<=>
') would be a binary operator taking two lvalues. It would swap the values held in the two locations. The swap operator can not be overloaded. It is automatically generated in terms of assignment. Swapping two values a and b of type A and B is equivalent to:
temp :A = a;
a = b;
b = temp;
The temp variable name is never accessible. Any conversions which might be legal under this rewrite are allowed. That is, if one can convert type A to type B and vice versa it is legal to swap to lvalues of those type. This most often occurs when the types are equal.
Example:
module
{
public class Entry
{
personal firstName :string;
personal lastName :string;
public swapFirstAndLastNames() -> void
{
firstName <=> lastName;
}
}
}