🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #173

Re: Exponentiation operator proposal

#173
From: Bill Hosken
Date: Tue, 15 Sep 1992 14:51
50 lines
2895 bytes
In article <1992Sep15.140027.17387@sunb10.cs.uiuc.edu>, pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
> In <1992Sep15.054226.4126@cc.tut.fi> jk87377@cc.tut.fi (Juhana Kouhia) writes:
> 
> >Hi,
> 
> >I'm very new in C++ world; I have not done any programs so far;
> >and I'm currently reading C++ Primer books on chapter 3   :-)
> 
> >Instead of making exponential operator; I would like to get
> >a new basic operation which allows programmer to define new
> >operations like 'a ** b'; that is, the '**' is defined.
> >('a pow b' is also good.)
> 
> *****>	The short answer is that it's a _real_ pain.  The somewhat
> 	longer answer is that making new operators means that you have
> 	to also establish the precedence and associativity of the new
> 	operator relative to all the other operators *AND* any other
> 	operators created by other people.  Every time an operator is
> 	added, the hierarchy would have to be readjusted.
> 
> 	For new operators, the precedence and associativity may seem
> 	arbitary at the time of creation, but it may later be realised,
> 	after experience, that it could have been done better...of
> 	course it's too late to change it now because code would break.
> 
> 	Also, if you were to use library X and library Y, each could use
> 	the same operator for different reasons, and the two operators
> 	were developed without regard to the others precedence and
> 	associativity; how would the compiler resolve this?  (I'm not
> 	looking for people to show how smart they are here by telling me
> 	how a compiler could resolve this...the point is that even if
> 	the compiler could do it, most _people_ would have a tough time
> 	looking at the code.)
> 
> 	It's more trouble than its worth.  The _point_ of operator
> 	overloading is to give an operator a _natural_ extension to
> 	another type.  People shouldn't sit around trying to figure out
> 	how to force an operator (square peg) to be used for a new type
> 	(round hole).  If the operator's use in a new context isn't
> 	intuitively obvious, forget it and use function-notation.

To illustrate these points, consider the << operator.

cout << 1 ? 2 : 3 ;

The result is a little hard to figure out until you remember
the precedence rules.

---------------
Bill.
Technical Details
Message-ID: <1992Sep15.145119.29289@spss.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sun-barr!olivea!spool.mu.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uchinews!spssig.spss.com!hosken
References: <23660@alice.att.com> <HBF.92Sep14205333@durin.uio.no> <1992Sep15.054226.4126@cc.tut.fi> <1992Sep15.140027.17387@sunb10.cs.uiuc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sun-barr!olivea!spool.mu.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uchinews!spssig.spss.com!hosken
From: hosken@spss.com (Bill Hosken)
Newsgroups: comp.std.c++,comp.lang.c++
Subject: Re: Exponentiation operator proposal
Message-ID: <1992Sep15.145119.29289@spss.com>
Date: 15 Sep 92 14:51:19 GMT
References: <23660@alice.att.com> <HBF.92Sep14205333@durin.uio.no> <1992Sep15.054226.4126@cc.tut.fi> <1992Sep15.140027.17387@sunb10.cs.uiuc.edu>
Sender: news@spss.com (Net News Admin)
Organization: SPSS, Inc.
Lines: 50