[Issue 9786] New: Allow [non-member|UFCS] implementation of operators

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 22 14:50:19 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9786

           Summary: Allow [non-member|UFCS] implementation of operators
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: monarchdodra at gmail.com


--- Comment #0 from monarchdodra at gmail.com 2013-03-22 14:50:18 PDT ---
UFCS has made it possible for anyone to "expand" a type, by giving it new
functions, or new properties. One of the rationales is that it improves
encapsulation by not having to worry on if or if not some function is member or
global. It also improves encapsulation by allowing expanding a type externally.

However, the line is drawn at operators: These may *only* be implemented as
member functions. I see no real reason for this limitation.

Issue 7177 has shown a (very) strong need for the ability to implement opDollar
via non-member:
http://d.puremagic.com/issues/show_bug.cgi?id=7177

One of the reasons for not implementing non-member operators is that it would
grant the ability to add operators on built in type. I think that:
a) If user wants to do something stupid, that's his problem.
b) If we so desire, I'm sure the compiler could be more than powerful enough to
implement "@disable opBinary" for any operator it does NOT want implemented
ever (eg string + string). Since the lookup rules are chose member function
first, this would not even be a "special case".

Anyways, yeah: non-member operators. We need them, and they make sense (IMO).

In particular, opDollar, since it is a property operator.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list