| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
October 10, 2007 Swap operator ? | ||||
|---|---|---|---|---|
| ||||
Not really nessesary, but nice to have... int a = 1; int b = 2; a <=> b // a == 2, b == 1 | ||||
October 10, 2007 Re: Swap operator ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BLS | BLS wrote:
> Not really nessesary, but nice to have...
> int a = 1;
> int b = 2;
> a <=> b // a == 2, b == 1
i use:
void swap(T)(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
int a = 1;
int b = 2;
swap(a,b);
| |||
October 10, 2007 Re: Swap operator ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BLS | BLS wrote: > Not really nessesary, but nice to have... > int a = 1; > int b = 2; > a <=> b // a == 2, b == 1 Or multiple return values, and then: a, b = b, a; -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi | |||
October 11, 2007 Re: Swap operator ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Matti Niemenmaa | Matti Niemenmaa wrote:
> BLS wrote:
>> Not really nessesary, but nice to have...
>> int a = 1;
>> int b = 2;
>> a <=> b // a == 2, b == 1
>
> Or multiple return values, and then:
>
> a, b = b, a;
>
This is the *python* way, and I love that too.
| |||
October 11, 2007 Re: Swap operator ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BLS | BLS schrieb:
> Not really nessesary, but nice to have...
> int a = 1;
> int b = 2;
> a <=> b // a == 2, b == 1
Sorry folks, just have recognized that this stuff is allready part of the chapel thread; B
| |||
October 11, 2007 Re: Swap operator ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Michael Gnail | Michael Gnail wrote:
> Matti Niemenmaa wrote:
>> BLS wrote:
>>> Not really nessesary, but nice to have...
>>> int a = 1;
>>> int b = 2;
>>> a <=> b // a == 2, b == 1
>>
>> Or multiple return values, and then:
>>
>> a, b = b, a;
>>
> This is the *python* way, and I love that too.
I don't know where that syntax came from, but but I'm pretty sure it predates python by a good bit. Probably Ada or something.
--bb
| |||
October 12, 2007 Re: Swap operator ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | On Fri, Oct 12, 2007 at 08:15:30AM +0900, Bill Baxter wrote:
>>> a, b = b, a;
>>>
>> This is the *python* way, and I love that too.
>
> I don't know where that syntax came from, but but I'm pretty sure it predates python by a good bit. Probably Ada or something.
Ada doesn't have multiple assignment. CLU had it in 1974, though.
David
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply