Random Suggestion: Swap Operator <=>?

Julian Salazar julian at ifeelrandom.com
Thu Jul 16 17:14:43 PDT 2009


I'm wondering, who here would use a swap operator if it were available?

Something that would be normally achieved through:
temp = a;
a = b;
b = temp;
or for the more bit-wise ;)
a ^= b;
b ^= a;
a ^= b;

It's something I've never actually seen implemented in any higher level 
language, but finds uses in linked lists, binary trees, and other data 
structures and algorithms. Temp wouldn't need to be an addressable value, so 
theoretically this operator (which I propose to be "<=>") could be 
compiler-optimized into an x86 xchg opcode for example. It could properly 
deal with references, data structures, class instances, etc. and not require 
the programmer to worry about these details.

I know that the chance of it actually being implemented is close to nil, but 
even a template in the standard library for it would be cool (or did I miss 
something?). Or am I being deluded? :) 




More information about the Digitalmars-d mailing list