From 4399764013592275906
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,aa85ef39cb5c6444,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-05-05 09:08:58 PST
Path: sparky!uunet!usc!sdd.hp.com!hp-cv!ogicse!news.u.washington.edu!sumax!thebes!manutius!garyp
From: garyp@manutius.UUCP (Gary Powell)
Newsgroups: comp.std.c++
Subject: Proposal for user defined operaters.
Message-ID: <643@manutius.UUCP>
Date: 5 May 92 16:08:58 GMT
Article-I.D.: manutius.643
Reply-To: garyp@manutius.UUCP (Gary Powell)
Organization: Aldus Corporation, Seattle WA
Lines: 63


I would like to add to the C++ language definition the notion of user defined
operators.  These would be defined with the same scoping rules as functions
but would have user defined precedence. The names allowed would exclude all 
reserved  names, ie extern, delete etc.

In order to specify precedence some sort of new keyword is required.  I 
propose:
precedence level # {
    declaration;
};

Where "#" is some integer between 0 and MAX_INTEGER.

eg:
class X {
...
public:
    friend X& operator foo(type_specifer rhs,type_specifier lhs) { ... };
    precidence level 10 { foo(type_specifer, type_specifier); };
...
};

Where one could say,
   
main ()
{
    X x, y, c;

    // ... sort of initialization ... 

    c = x foo y;

}

Why?
This would allow for writing operators for matrix math.  While they lack the
cryptic notation of APL it would be easier to read than the current
technique of bending automic types to fit.  Allowing only declarators of the
same rules as fns would prevent creating code no one could read.  Or at
least no worse than the current mess. 

Problems:
Precedence order rules could create a mess for inexperienced programmers.

Ie: current method.
   foo(x,foo(c,y));
      vs
   x foo ( c foo y );
      or 
   x foo c foo y;


This is a fishing expedition.  I welcome comments, suggestions places to
put this proposal.

As usual, the ideas expressed here are mine and not necessarily those of
my employer.

Gary Powell ------------+ Internet:	garyp@camco.aldus.com
c/o Aldus Corporation	| uunet:	manutius!garyp@uunet.uu.net
411 1st Ave South	| uucp:		camco!manutius!garyp
Seattle, WA 98104  USA	| Voice:	(206) 622-5500


