Random Suggestion: Swap Operator <=>?

Julian Salazar julian at ifeelrandom.com
Fri Jul 17 17:51:15 PDT 2009


"Walter Bright" <newshound1 at digitalmars.com> wrote in message 
news:4A610016.2040104 at digitalmars.com...
> Ary Borenszweig wrote:
>> Oh, come on, It's just three lines of code! And it's not *that* common. I 
>> know it's kind of basic and primitive, but there's a standard library 
>> function for it. Why add an operator *just* for that?
>
> A request for a swap operators comes up now and then in the C/C++ forums 
> as well. The answer given, which applies to D as well, is that:
>
> 1. it is too rarely used to merit a special operator just for it
>
> 2. it is handled adequately with library code or even just inlining it

Well, when was the last time you used "!<="? Ah well, my ignorance of the 
swap library template has sparked debate. Sorry, I'll make sure to search 
better next time.

But I'm wondering, what's your opinion of the generalized tuple assignment 
syntax talked about above? Or more generally, supporting tuples in the 
language?
// Swap
a, b = b, a;
// Fibonacci!
a, b = b, a+b;
// Switching positions with the previous item in a doubly linked list, just 
cause ;)
item.prev.prev, item.prev.next, item.next, item.prev, item.prev.prev.next, 
item.next.prev = item.prev.next, item.next, item.prev, item.prev.prev, item, 
item.prev;

Okay, maybe I'll stop now... 




More information about the Digitalmars-d mailing list