digitalmars.D - Exchange Operator
- Tu Nam (8/8) May 09 2004 I see in Extended C :http://web.ss.pub.ro/~vycxs/ecdk/ecl_x.htm
- Walter (5/13) May 09 2004 optExchange
- Tu Nam (4/17) May 10 2004 Well , the first use I just thought is in sorting algorithms.
- Ilya Minkov (3/5) May 10 2004 How about a function tenplate in a coming up standard template library?
- Matthew (4/9) May 10 2004 Yes, I've added one in DTL. But because templates are not implicitly
- Matthew (3/11) May 09 2004 I'd very much like this, but only if opSwap was available for UDTs
- Alex Fitzpatrick (12/22) May 10 2004 I like the idea... it should be possible to optimise for lots of types t...
- Matthew (3/23) May 10 2004 None of them are as clear, to me at least, as <->
- Juan C (17/25) May 10 2004
- Norbert Nemec (8/24) May 10 2004 I agree in so far, that new operators should be consider with special ca...
I see in Extended C :http://web.ss.pub.ro/~vycxs/ecdk/ecl_x.htm has an exchange operator which very , very notable : x=0; y=3; Just write : x<->y so x=3;y=0; Whether D can make a builtin exchange operator like that , and a optExchange for exchange operator overloading ?
May 09 2004
"Tu Nam" <dreamweaver mail15.com> wrote in message news:c7mtv3$10p4$1 digitaldaemon.com...I see in Extended C :http://web.ss.pub.ro/~vycxs/ecdk/ecl_x.htm has an exchange operator which very , very notable : x=0; y=3; Just write : x<->y so x=3;y=0; Whether D can make a builtin exchange operator like that , and aoptExchangefor exchange operator overloading ?This comes up now and then, and it's a seductive idea. But there just doesn't seem to be enough utility in it to justify making it an operator.
May 09 2004
Well , the first use I just thought is in sorting algorithms. That operator is more be useful in sort . "Walter" <newshound digitalmars.com> wrote in message news:c7muj8$11je$1 digitaldaemon.com..."Tu Nam" <dreamweaver mail15.com> wrote in message news:c7mtv3$10p4$1 digitaldaemon.com...I see in Extended C :http://web.ss.pub.ro/~vycxs/ecdk/ecl_x.htm has an exchange operator which very , very notable : x=0; y=3; Just write : x<->y so x=3;y=0; Whether D can make a builtin exchange operator like that , and aoptExchangefor exchange operator overloading ?This comes up now and then, and it's a seductive idea. But there just doesn't seem to be enough utility in it to justify making it an operator.
May 10 2004
How about a function tenplate in a coming up standard template library? -eye Tu Nam schrieb:Well , the first use I just thought is in sorting algorithms. That operator is more be useful in sort .
May 10 2004
Yes, I've added one in DTL. But because templates are not implicitly instantiated, it's a fair amount of eye candy. "Ilya Minkov" <minkov cs.tum.edu> wrote in message news:c7oho2$fnn$2 digitaldaemon.com...How about a function tenplate in a coming up standard template library? -eye Tu Nam schrieb:Well , the first use I just thought is in sorting algorithms. That operator is more be useful in sort .
May 10 2004
I'd very much like this, but only if opSwap was available for UDTs "Tu Nam" <dreamweaver mail15.com> wrote in message news:c7mtv3$10p4$1 digitaldaemon.com...I see in Extended C :http://web.ss.pub.ro/~vycxs/ecdk/ecl_x.htm has an exchange operator which very , very notable : x=0; y=3; Just write : x<->y so x=3;y=0; Whether D can make a builtin exchange operator like that , and a optExchange for exchange operator overloading ?
May 09 2004
Tu Nam wrote:I see in Extended C :http://web.ss.pub.ro/~vycxs/ecdk/ecl_x.htm has an exchange operator which very , very notable : x=0; y=3; Just write : x<->y so x=3;y=0; Whether D can make a builtin exchange operator like that , and a optExchange for exchange operator overloading ?I like the idea... it should be possible to optimise for lots of types too. Just to keep the conversation going, how about: x<=>y or x:=:y or x:-:y or x<~>y -- Alex
May 10 2004
Tu Nam wrote:That's already an operator (comparison) in Ruby. To overload that would be confusing.I see in Extended C :http://web.ss.pub.ro/~vycxs/ecdk/ecl_x.htm has an exchange operator which very , very notable : x=0; y=3; Just write : x<->y so x=3;y=0; Whether D can make a builtin exchange operator like that , and a optExchange for exchange operator overloading ?I like the idea... it should be possible to optimise for lots of types too. Just to keep the conversation going, how about: x<=>yor x:=:y or x:-:y or x<~>yNone of them are as clear, to me at least, as <->
May 10 2004
<snip></snip> I dunno... of course I'm against any new operators anyway, but this in particular may cause trouble, methinks. I expect it would be fine for ints and such, but for instances of objects I would expect it to simply exchange the values of the references, not the contents (certainly much faster). But this is where the trouble would come in, what if I have an array of MyObjs that I want to sort (with a bubble sort for instance) and use two references: Ofront and Oback, when I use: Ofront <-> OBack to exchange them it would have no effect on the array. So newbies would have to be trained to use indices rather than references to array members: MyArray [ ifront ] <-> MyArray [ iback ] which is not as clear, but better than not having the exchange operator. Certainly it has some value, but also causes potential for trouble. Anyway... mightn't it be better to leave well enough alone and not cause the same kind of confusion that that D strings cause with printf() ?I see in Extended C :http://web.ss.pub.ro/~vycxs/ecdk/ecl_x.htm has an exchange operator which very , very notable : x=0; y=3; Just write : x<->y so x=3;y=0; Whether D can make a builtin exchange operator like that , and a optExchange for exchange operator overloading ?
May 10 2004
Juan C wrote:I dunno... of course I'm against any new operators anyway,I agree in so far, that new operators should be consider with special care. They should be descriptive, and they should not be used where similar actions might be mixed up. They should not be overloaded with different meaning in different context. Apart from that, I really have no problems with new operators. The fact that I have to learn something new does not mean that it is bad.I expect it would be fine for ints and such, but for instances of objects I would expect it to simply exchange the values of the references, not the contents (certainly much faster). But this is where the trouble would come in, what if I have an array of MyObjs that I want to sort (with a bubble sort for instance) and use two references: Ofront and Oback, when I use: Ofront <-> OBack to exchange them it would have no effect on the array. So newbies would have to be trained to use indices rather than references to array members: MyArray [ ifront ] <-> MyArray [ iback ] which is not as clear, but better than not having the exchange operator. Certainly it has some value, but also causes potential for trouble.I don't think that confusion would be worse than for the = operator.
May 10 2004