Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!gatech!hubcap!ncrcae!ncr-sd!hp-sdd!hp-pcd!hplsla!jima From: jima@hplsla.HP.COM (Jim Adcock) Newsgroups: comp.lang.c++ Subject: Re: Some comments on Lippman's Message-ID: <6590239@hplsla.HP.COM> Date: 7 Sep 89 19:35:37 GMT References: Organization: HP Lake Stevens, WA Lines: 72 / hplsla:comp.lang.c++ / jima@hplsla.HP.COM (Jim Adcock) / 11:08 am Sep 7, 1989 / // >Grandi: No mention is made of the newly overloadable "," operator. It would // >be interesting to see cases in which it is useful. //---------------------------------------------------------------- // Quick example of overloading in order to turn C++ into // a concurrent language, where semicolons continue to indicate processes // are to be executed in sequence, and colons indicate processes are to // be executed simultaneously. [Too bad C++ insists that the un-overloaded // comma operator evaluate left-to-right including side effects. This // unfortunate restriction is not applied to the more common usage of comma // in function argument lists! If this context dependent restriction could // be relaxed then C++ could naturally be applied to multi-processing CPUs, // with semicolon continuing to mean sequencing, and comma indicating // parallelism.] // [Probably requires a 2.0 compatible compiler] #include // bogus process classes -- just a quick example! class multiprocess { friend class process; const process *p; const multiprocess *l; const multiprocess *r; public: multiprocess() : p(0), l(0), r(0) {} multiprocess(const process& P):p(&P),l(0),r(0) {} multiprocess(const multiprocess& L):p(0),l(&L),r(0){} multiprocess(const multiprocess& L, const multiprocess& R): p(0), l(&L) {printf("simultaneously "); r=&R;} const multiprocess& operator,(const multiprocess& that) const {return *(new multiprocess(*this,that));} }; class process { friend class multiprocess; const char *s; public: process(const char *S):s(S){} const process& operator()() const {printf("%s() ",s); return *this;} const multiprocess& operator,(const multiprocess& that) const {return (multiprocess(*this)).operator,(that);} }; void inline nl(){putchar('\n');} void main() { process do_this("do_this"); process do_that("do_that"); process and_do_the_other_thing("and_do_the_other_thing"); //semicolons indicates executing processes in sequence: do_this(); nl(); do_that(); nl(); and_do_the_other_thing(); nl(); nl(); //whereas commas indicate executing processes simultaneously: do_this(), do_that(), and_do_the_other_thing(); nl(); }