TIP: Click on subject to list as thread! ANSI
echo: nthelp
to: Paul Ranson
from: Tony Williams
date: 2004-11-22 13:50:34
subject: Re: C++ for beginners?

From: Tony Williams 

Yep, that's right. It's just the old xor trick written on one line by
taking advantage of the right associativity of operators. It should work on
all atomic types, so floats and pointers will work but not C++ style
strings.

And no, I would never seriously advocate using it for all the reasons you
state. But hey, at least I used references instead of pointers ...

--
Tony

On 11/21/2004 03:13 PM, Paul Ranson wrote:
> IIRC the '^' operator is 'xor'. I suspect it boils down to,
>
> x = x ^ y ;
> y = y ^ x ;
> x = x ^ y ;
>
> therefore it resolves to y = y ^ x ^ y ; or x and x = x ^ y ^ y ^ x ^ y ; or
> y. Probably not going to work for strings or floats. And I suspect real
> computers and real compilers will run a conventional swap at least as fast.
>
> BTW STL includes 'swap' as a template, use it...
>
> Paul
>
> "Geo"  wrote in message
news:41a10f7e$2{at}w3.nls.net...
>
>>"Tony Williams"  wrote in message
>>news:41a10437$1{at}w3.nls.net...
>>
>>
>>>     x ^= y ^= x ^= y;
>>
>>
>>>There, that's much harder to understand 
>>
>>Ok now explain what ^= does.
>>
>>Geo.
>>
>>
>
>
>

--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)
SEEN-BY: 633/267 270 5030/786
@PATH: 379/45 1 396/45 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.