www.digitalmars.com         C & C++   DMDScript  

D - dmd 0.37 release - operator overloading

reply "Walter" <walter digitalmars.com> writes:
ftp://www.digitalmars.com/dmdalpha.zip

www.digitalmars.com/d/operatoroverloading.html

It doesn't do all the operators yet, but it's a start.

-Walter
Aug 18 2002
next sibling parent reply "anderson" <anderson firestar.com.au> writes:
Great Job!

"Walter" <walter digitalmars.com> wrote in message
news:ajq4fo$311i$1 digitaldaemon.com...
 ftp://www.digitalmars.com/dmdalpha.zip

 www.digitalmars.com/d/operatoroverloading.html

 It doesn't do all the operators yet, but it's a start.

 -Walter
Aug 19 2002
parent "Walter" <walter digitalmars.com> writes:
The neat thing is it turned out to be an amazingly small amount of code
added to the source. -Walter

"anderson" <anderson firestar.com.au> wrote in message
news:ajqtvc$rg0$1 digitaldaemon.com...
 Great Job!

 "Walter" <walter digitalmars.com> wrote in message
 news:ajq4fo$311i$1 digitaldaemon.com...
 ftp://www.digitalmars.com/dmdalpha.zip

 www.digitalmars.com/d/operatoroverloading.html

 It doesn't do all the operators yet, but it's a start.

 -Walter
Aug 19 2002
prev sibling next sibling parent reply "anderson" <anderson firestar.com.au> writes:
I don't understand point 4.

"4. If a or b is a struct or class object reference, it is an error. "

Do you mean?

"4. If a and b is a struct or class object reference, it is an error. "

If so do you plan on making class by class operations overloadable in a
future?

Can you add an example for 4.?

"Walter" <walter digitalmars.com> wrote in message
news:ajq4fo$311i$1 digitaldaemon.com...
 ftp://www.digitalmars.com/dmdalpha.zip

 www.digitalmars.com/d/operatoroverloading.html

 It doesn't do all the operators yet, but it's a start.

 -Walter
Aug 19 2002
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
I believe that 4 is a fall-through if options 1-3 fail.  If you've tried to
use an operator, and the classes offer no way to relate them, then it is an
error.

anderson wrote:

 I don't understand point 4.

 "4. If a or b is a struct or class object reference, it is an error. "

 Do you mean?

 "4. If a and b is a struct or class object reference, it is an error. "

 If so do you plan on making class by class operations overloadable in a
 future?

 Can you add an example for 4.?

 "Walter" <walter digitalmars.com> wrote in message
 news:ajq4fo$311i$1 digitaldaemon.com...
 ftp://www.digitalmars.com/dmdalpha.zip

 www.digitalmars.com/d/operatoroverloading.html

 It doesn't do all the operators yet, but it's a start.

 -Walter
-- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Aug 19 2002
parent "Walter" <walter digitalmars.com> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3D611181.FE5B9F74 deming-os.org...
 I believe that 4 is a fall-through if options 1-3 fail.  If you've tried
to
 use an operator, and the classes offer no way to relate them, then it is
an
 error.
That's right.
Aug 19 2002
prev sibling next sibling parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Very good!  Now, on to the op= operators...since they are often much
faster and memory efficient to implement :)

In fact, in my mathematical classes in C++, I would often implement op
as derived from op= .  I would create a temporary copy of an object, use
the op= function on that, and then return the temporary...

Walter wrote:

 ftp://www.digitalmars.com/dmdalpha.zip

 www.digitalmars.com/d/operatoroverloading.html

 It doesn't do all the operators yet, but it's a start.

 -Walter
-- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Aug 19 2002
prev sibling next sibling parent reply Jonathan Andrew <jon ece.arizona.edu> writes:
Walter wrote:

 ftp://www.digitalmars.com/dmdalpha.zip

 www.digitalmars.com/d/operatoroverloading.html

 It doesn't do all the operators yet, but it's a start.

 -Walter
I don't think it gets much simpler than that. I agree with anderson, good job! -Jon
Aug 19 2002
parent "Walter" <walter digitalmars.com> writes:
"Jonathan Andrew" <jon ece.arizona.edu> wrote in message
news:3D611674.3D0C2921 ece.arizona.edu...
 I don't think it gets much simpler than that. I agree with anderson,
 good job!
Thanks! I've sinced added a blurb to www.digitalmars.com/d/cpptod.html to highlight the difference between the D way and the C++ way.
Aug 19 2002
prev sibling next sibling parent reply "Sean L. Palmer" <seanpalmer earthlink.net> writes:
What happened to the nice Vector operator (Vector a) + (Vector b) {} syntax
everyone was voting for?  You figured out a way around the friend problem.
Some things just don't properly belong in either class and should be sorta
global.

Sean

"Walter" <walter digitalmars.com> wrote in message
news:ajq4fo$311i$1 digitaldaemon.com...
 ftp://www.digitalmars.com/dmdalpha.zip

 www.digitalmars.com/d/operatoroverloading.html

 It doesn't do all the operators yet, but it's a start.

 -Walter
Aug 19 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
news:ajr7iv$1ddn$1 digitaldaemon.com...
 What happened to the nice Vector operator (Vector a) + (Vector b) {}
syntax
 everyone was voting for?
I believe that adds significant complexity to the language, whereas the naming convention route offers equivalent power (or even more power, as the functions can be virtual, variadic, etc.) very simply.
 You figured out a way around the friend problem.
Yes, that one had me stumped for a while.
 Some things just don't properly belong in either class and should be sorta
 global.
I agree, but since the desired result can be adequately addressed with the member syntax, I thought adding more syntax for global functions was not worth the cost.
Aug 19 2002
parent reply "Sean L. Palmer" <seanpalmer earthlink.net> writes:
It'll do.  ;)

Now if I can just get a windows.d that has GetFocus() and PeekMessage() in
it...  I'll be in business!

Sean

"Walter" <walter digitalmars.com> wrote in message
news:ajrat2$1kdf$1 digitaldaemon.com...
 "Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
 news:ajr7iv$1ddn$1 digitaldaemon.com...
 What happened to the nice Vector operator (Vector a) + (Vector b) {}
syntax
 everyone was voting for?
I believe that adds significant complexity to the language, whereas the naming convention route offers equivalent power (or even more power, as
the
 functions can be virtual, variadic, etc.) very simply.

 You figured out a way around the friend problem.
Yes, that one had me stumped for a while.
 Some things just don't properly belong in either class and should be
sorta
 global.
I agree, but since the desired result can be adequately addressed with the member syntax, I thought adding more syntax for global functions was not worth the cost.
Aug 19 2002
next sibling parent "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
news:ajsoge$7sn$1 digitaldaemon.com...
 Now if I can just get a windows.d that has GetFocus() and PeekMessage() in
 it...  I'll be in business!
ok, ok!
Aug 20 2002
prev sibling next sibling parent Pavel Minayev <evilone omen.ru> writes:
On Mon, 19 Aug 2002 23:52:52 -0700 "Sean L. Palmer" <seanpalmer earthlink.net> 
wrote:

 It'll do.  ;)
 
 Now if I can just get a windows.d that has GetFocus() and PeekMessage() in
 it...  I'll be in business!
Grab it! This is the latest version used by WinD, and it's hand-coded (unlike my old windows.d). I hope that Walter will merge it with his API declarations.
Aug 20 2002
prev sibling parent Pavel Minayev <evilone omen.ru> writes:

Aug 20 2002
prev sibling next sibling parent reply Joe Battelle <Joe_member pathlink.com> writes:
"where a is a class or struct object reference..."
Did I miss something or are we getting concrete types (in C++ parlance) as well?
All the examples show class and not struct so--maybe not yet?
Aug 19 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Joe Battelle" <Joe_member pathlink.com> wrote in message
news:ajr888$1eqp$1 digitaldaemon.com...
 "where a is a class or struct object reference..."
 Did I miss something or are we getting concrete types (in C++ parlance) as
well?
 All the examples show class and not struct so--maybe not yet?
The struct overloading is implemented.
Aug 19 2002
parent reply Joe Battelle <Joe_member pathlink.com> writes:
The struct overloading is implemented.
Just for operator members or have you added methods to structs in the general case?
Aug 19 2002
parent reply Pavel Minayev <evilone omen.ru> writes:
On Mon, 19 Aug 2002 18:19:03 +0000 (UTC) Joe Battelle 
<Joe_member pathlink.com> wrote:

 Just for operator members or have you added methods to structs in the general
 case?
They were added loooong ago.
Aug 19 2002
parent Joe Battelle <Joe_member pathlink.com> writes:
They were added loooong ago.
Sorry about that, I kept reading this line from the Structs documentation: "Member functions and static members are allowed." as though it had a _not_ in it. Weird, there's a not right above it--maybe my brain grabbed on to that one :)
Aug 19 2002
prev sibling next sibling parent reply Pavel Minayev <evilone omen.ru> writes:
On Sun=2C 18 Aug 2002 23=3A53=3A48 -0700 =22Walter=22
=3Cwalter=40digitalmars=2Ecom=3E wrote=3A

=3E ftp=3A=2F=2Fwww=2Edigitalmars=2Ecom=2Fdmdalpha=2Ezip
=3E 
=3E www=2Edigitalmars=2Ecom=2Fd=2Foperatoroverloading=2Ehtml
=3E 
=3E It doesn't do all the operators yet=2C but it's a start=2E

Great=2E Not the syntax I was expecting=2C frankly=2C but hey - it works=2C and
does its job well! Now=2C as soon as we get all operators =28by the way=2C
will binary ~ and ~=3D be supported=3F I hope so!=29=2C only templates would
be left of important C++ functionality not covered by D=2E=2E=2E

By the way=2E=2E=2E I proposed this once before=2C but back then=2C operator
overloading wasn't implemented=2E What about input and output operators=2C
for example -=3E and =3C-=2C to use them for streams and alike where
C++ overloads =3E=3E and =3C=3C=2E They wouldn't be allowed on global types=2C
so you'd have to overload them=2E But it could be useful=3A

=09int main=28=29
=09{
=09=09char=5B=5D name=3B
=09=09cout =3C- =22Enter your name=3A =22=3B
=09=09cin -=3E name=3B
=09=09cout =3C- =22Hello=2C =22 =3C- name =3C- =22!=5Cn=22=3B
=09=09return 0=3B
=09}

Well=2C you get the idea=2E It could also be some other operator=2C

care really=2C it would be just great if there was some better
way to output data then printf=28=29=2E 
Aug 19 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:CFN374879772193056 news.digitalmars.com...
Great. Not the syntax I was expecting, frankly, but hey - it works, and
does its job well! Now, as soon as we get all operators (by the way, will binary ~ and ~= be supported? I hope so!), Yes, I just forgot them for the moment.
only templates would be left of important C++ functionality not covered by
D... With a much simpler language!
By the way... I proposed this once before, but back then, operator
overloading wasn't implemented. What about input and output operators, for example -> and <-, to use them for streams and alike where C++ overloads >> and <<. They wouldn't be allowed on global types, so you'd have to overload them. But it could be useful: I confess I just never liked the idea behind iostreams and the overloaded operators for it. It just never looked right or elegant. It also always seemed to result in fat exe's.
Aug 19 2002
parent reply Pavel Minayev <evilone omen.ru> writes:
On Mon, 19 Aug 2002 16:16:11 -0700 "Walter" <walter digitalmars.com> wrote:

 I confess I just never liked the idea behind iostreams and the overloaded
 operators for it. It just never looked right or elegant. It also always
 seemed to result in fat exe's.
Alternative? Unless you give us safe varargs, of course... =)
Aug 20 2002
next sibling parent "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:CFN374884942340972 news.digitalmars.com...
 On Mon, 19 Aug 2002 16:16:11 -0700 "Walter" <walter digitalmars.com>
wrote:
 I confess I just never liked the idea behind iostreams and the
overloaded
 operators for it. It just never looked right or elegant. It also always
 seemed to result in fat exe's.
Alternative? Unless you give us safe varargs, of course... =)
My grand idea is mumble - mumble - mumble, and so you see, it is brilliant! But seriously, at the moment I'm working on the generics issue. I hope to have a strawman for that by the end of the month. -Walter
Aug 20 2002
prev sibling parent "Alix Pexton" <Alix seven-point-star.co.uk> writes:
I always thought it would be nice to specify varargs with simple
regular(ish) expressions, something similar to the syntax used
in a DTD would be sufficient. The only problem with a direct lift is the *

Then all you have to do is have a way of correctly reading the arguments
regardless of how the expression is matched. That I'd leave up to you
(points wildly in random, generally leftward direction)...

-- 
Alix Pexton...

Webmaster, The D Journal
web: www.thedjournal.com
email:webmaster thedjournal.com
"The D journal, a work in progress..."

Pavel Minayev <evilone omen.ru> wrote in article
<CFN374884942340972 news.digitalmars.com>...
 On Mon, 19 Aug 2002 16:16:11 -0700 "Walter" <walter digitalmars.com>
wrote:
 
 I confess I just never liked the idea behind iostreams and the
overloaded
 operators for it. It just never looked right or elegant. It also always
 seemed to result in fat exe's.
Alternative? Unless you give us safe varargs, of course... =)
Aug 21 2002
prev sibling parent reply "Carlos" <carlos8294 msn.com> writes:
Hi all...
Outlook Express did a weird thing and started to download ALL the messages
in this newsgroup (I stopped before it was finished), but it was good
because I found this post, which dates 2001-08-17. Not many of us were in
this newsgroup in that time, so probably most won't know of its existence
(and also, many of those who used to post back then don't post now).
Well... What do you guys (Walter especially) think about it?

Walter wrote:
 Charles Hixson wrote in message <3B7D2C6B.4040702 earthlink.net>...
 ...So one could define :+: to add
matrices, etc., and as these would really be functions, they should
follow the normal overloading rules of functions.

This would allow them to be easily parsed, would distinguish them
clearly from the standard operators, and would provide the majority of
the notational compactness that normal operators provide.  The fact that
A :+: B would be syntactic sugar for A.add (B) is minor, but convenient.
   As to precedence ... they should probably bind more strongly than any
other operator, and all to the same degree.  If you want to get fancy,
you'ld need to use parentheses.
Now this idea has a lot of merit! Thanks for posting it. I *like* it being clearly distinguishable from the native operators.
Aug 21 2002
next sibling parent reply "Walter" <walter digitalmars.com> writes:
"Carlos" <carlos8294 msn.com> wrote in message
news:ak1n98$utk$1 digitaldaemon.com...
 Hi all...
 Outlook Express did a weird thing and started to download ALL the messages
 in this newsgroup (I stopped before it was finished), but it was good
 because I found this post, which dates 2001-08-17. Not many of us were in
 this newsgroup in that time, so probably most won't know of its existence
 (and also, many of those who used to post back then don't post now).
 Well... What do you guys (Walter especially) think about it?
Ah, the ghost of postings past <g>. I was wrong. The trouble with :+: being for overloaded operators and + for builtin operators is that generic templates don't work. It has to be the same operator token.
Aug 21 2002
parent reply "Carlos" <carlos8294 msn.com> writes:
 I was wrong. The trouble with :+: being for overloaded operators and + for
 builtin operators is that generic templates don't work. It has to be the
 same operator token.
Ok, but I mainly meant about the other stuff... About using other symbols as operators...
Aug 21 2002
next sibling parent "Walter" <walter digitalmars.com> writes:
"Carlos" <carlos8294 msn.com> wrote in message
news:ak21oi$30gn$1 digitaldaemon.com...
 Ok, but I mainly meant about the other stuff... About using other symbols
as
 operators...
I still like that idea.
Aug 22 2002
prev sibling parent reply "Sean L. Palmer" <seanpalmer earthlink.net> writes:
I want to use Unicode math symbols as operators ;)  Dot and cross product
etc.  Union, Intersection.  Almost Equal To.  Similar To.  So many things
that are standard math symbols and are hard to type out with words.

Sean

"Carlos" <carlos8294 msn.com> wrote in message
news:ak21oi$30gn$1 digitaldaemon.com...
 I was wrong. The trouble with :+: being for overloaded operators and +
for
 builtin operators is that generic templates don't work. It has to be the
 same operator token.
Ok, but I mainly meant about the other stuff... About using other symbols
as
 operators...
Aug 22 2002
next sibling parent "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
news:ak3600$231d$1 digitaldaemon.com...
 I want to use Unicode math symbols as operators ;)  Dot and cross product
 etc.  Union, Intersection.  Almost Equal To.  Similar To.  So many things
 that are standard math symbols and are hard to type out with words.
I've been thinking that it might be possible to predefine some of those as tokens, and then allow operator overloading of them.
Aug 22 2002
prev sibling parent reply "Juan Carlos Arevalo Baeza" <jcab JCABs-Rumblings.com> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
news:ak3600$231d$1 digitaldaemon.com...

 I want to use Unicode math symbols as operators ;)  Dot and cross product
 etc.  Union, Intersection.  Almost Equal To.  Similar To.  So many things
 that are standard math symbols and are hard to type out with words.
What text editor would you use to program, then? Ahem... Salutaciones, JCAB
Aug 22 2002
next sibling parent Pavel Minayev <evilone omen.ru> writes:
On Thu, 22 Aug 2002 13:12:54 -0700 "Juan Carlos Arevalo Baeza" 
<jcab JCABs-Rumblings.com> wrote:

    What text editor would you use to program, then? Ahem...
BeOS StyleEdit. Or QNX Ped. Or maybe just FAR. =)
Aug 22 2002
prev sibling parent reply "Sean L. Palmer" <seanpalmer earthlink.net> writes:
That's a good question, and I don't have a good answer.  But I do find it
hard to believe that UTF-8 and Unicode fonts have been around for this long
without some fool making a truly unicode compatible text editor.  I just
tried TextPad and though it claims Unicode and UTF-8 support for file
formats, it won't display the characters properly.

I suppose I could always use MS Word as an editor.  ;(

Sean

"Juan Carlos Arevalo Baeza" <jcab JCABs-Rumblings.com> wrote in message
news:ak3g7p$2edc$1 digitaldaemon.com...
 "Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
 news:ak3600$231d$1 digitaldaemon.com...

 I want to use Unicode math symbols as operators ;)  Dot and cross
product
 etc.  Union, Intersection.  Almost Equal To.  Similar To.  So many
things
 that are standard math symbols and are hard to type out with words.
What text editor would you use to program, then? Ahem... Salutaciones, JCAB
Aug 23 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
news:ak5p89$20d4$1 digitaldaemon.com...
 That's a good question, and I don't have a good answer.  But I do find it
 hard to believe that UTF-8 and Unicode fonts have been around for this
long
 without some fool making a truly unicode compatible text editor.  I just
 tried TextPad and though it claims Unicode and UTF-8 support for file
 formats, it won't display the characters properly.

 I suppose I could always use MS Word as an editor.  ;(
The source to MicroEmacs comes with the compiler. If the operating system can display unicode characters, then it would be fairly trivial to change ME to edit unicode.
Aug 23 2002
parent reply "Juan Carlos Arevalo Baeza" <jcab JCABs-Rumblings.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:ak5qb4$21dc$3 digitaldaemon.com...

 The source to MicroEmacs comes with the compiler. If the operating system
 can display unicode characters, then it would be fairly trivial to change
ME
 to edit unicode.
Display is one end of it. Input is another. How would you type the new characters in the editor? I've always seen UNICODE as a post-process stuff that kind of happens behind the scenes but you hardly ever see while you program. I would really _love_ to see a real, usable UNICODE editor in action. Salutaciones, JCAB
Aug 23 2002
next sibling parent reply "Walter" <walter digitalmars.com> writes:
"Juan Carlos Arevalo Baeza" <jcab JCABs-Rumblings.com> wrote in message
news:ak6ftm$2p80$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:ak5qb4$21dc$3 digitaldaemon.com...

 The source to MicroEmacs comes with the compiler. If the operating
system
 can display unicode characters, then it would be fairly trivial to
change
 ME
 to edit unicode.
Display is one end of it. Input is another. How would you type the new characters in the editor? I've always seen UNICODE as a post-process stuff that kind of happens behind the scenes but you hardly ever see while you program. I would really _love_ to see a real, usable UNICODE editor in action.
Input it as: <METAKEY> UUUU Ugly, but workable for occaisonal use.
Aug 23 2002
parent reply "Sean L. Palmer" <seanpalmer earthlink.net> writes:
Just cut'n'paste from the Character Map tool.

Sean

"Walter" <walter digitalmars.com> wrote in message
news:ak6ktk$2uip$1 digitaldaemon.com...
 "Juan Carlos Arevalo Baeza" <jcab JCABs-Rumblings.com> wrote in message
 news:ak6ftm$2p80$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:ak5qb4$21dc$3 digitaldaemon.com...

 The source to MicroEmacs comes with the compiler. If the operating
system
 can display unicode characters, then it would be fairly trivial to
change
 ME
 to edit unicode.
Display is one end of it. Input is another. How would you type the
new
 characters in the editor? I've always seen UNICODE as a post-process
stuff
 that kind of happens behind the scenes but you hardly ever see while you
 program. I would really _love_ to see a real, usable UNICODE editor in
 action.
Input it as: <METAKEY> UUUU Ugly, but workable for occaisonal use.
Aug 24 2002
parent Pavel Minayev <evilone omen.ru> writes:
On Sat, 24 Aug 2002 11:52:35 -0700 "Sean L. Palmer" <seanpalmer earthlink.net> 
wrote:

 Just cut'n'paste from the Character Map tool.
Conclusion: any D IDE should support Unicode.
Aug 24 2002
prev sibling parent Pavel Minayev <evilone omen.ru> writes:
On Fri, 23 Aug 2002 16:25:58 -0700 "Juan Carlos Arevalo Baeza" 
<jcab JCABs-Rumblings.com> wrote:

    Display is one end of it. Input is another. How would you type the new
 characters in the editor? I've always seen UNICODE as a post-process stuff
There are different keyboard mappings, and many OSes allow you to create your own - so one could create such a mapping, for example I could do it for BeOS, and then just switch back and forth. Then the only problem would be to remember which key corresponds to which operator.
Aug 24 2002
prev sibling parent "Carlos" <carlos8294 msn.com> writes:
"Carlos" <carlos8294 msn.com> escribió en el mensaje
news:ak1n98$utk$1 digitaldaemon.com...
 Hi all...
 Outlook Express did a weird thing and started to download ALL the messages
 in this newsgroup (I stopped before it was finished), but it was good
You can call me crazy (actually, you'd be right if you do that ;) ), but I did it. I downloaded d in news.digitalmars.com. It's damn late here (over 3 in the morning), but I gues that reading 6700+ posts will help me learn more D. Yes, I have lots of reading. Let's see what happens...
Aug 22 2002