swap (a, b) suggestion
D. Hugh Redelmeier
hugh@redline.mimosa.com
Sun Jan 4 10:41:00 GMT 1998
[I'm replying to a reconstruction of the original message; sorry if I
botch it.]
On Sat, Jan 03, 1998 at 06:11:23PM -0500, Eric Buddington wrote:
| For integer values, the following works, and is significantly
| faster:
| template <class T>
| inline void swap(T& a, T& b) {
| a ^= b;
| b ^= a;
| a ^= b;
| }
If a and be are aliases, then this code won't work. I don't actually know
the specs for swap -- are aliases legal? I hope aliases are legal since
allowing degenerate cases simplifies programming.
Hugh Redelmeier
hugh@mimosa.com voice: +1 416 482-8253
More information about the Gcc
mailing list