[Issue 1255] New: operator overloading

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 3 01:33:24 PDT 2007


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

           Summary: operator overloading
           Product: D
           Version: 1.014
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: Daniel919 at web.de


Hi, I try to figure out, whether a port of boost::spirit to D would be
possible.
This library is heavily using C++ operator overloading.
Now there are some problems I figured out:
C++ allows the * operator to be overloaded in case of dereferencing.
Spirit uses it as the "kleene star": *(expr) means repeat expr 0 or more times.
D has opMul(_r), which overloads: "a*b" and "null*b", but not: "*b" since the
latter means dereferencing.
In the docs it's said "!", "&&" and "||" will likely never be overloadable.
C++ allows all of them to be overloaded and spirit makes use of it.
"!(expr)" means expr is optional (so 0 or 1 match). "||" and "&&" are used for
sequential matching.

So my feature req for D:
without further arguments:
*(expr) -> opDeref()
!(expr) -> opNot()
&(expr) -> opAddr()

WITH one more argument and _r:
expr1 && expr2 -> opAndAnd
expr1 || expr2 -> opOrOr
expr1 , expr2 -> opComma

The following is not possible in C++:
value = expr1 expr2;
Because nothing is not overloadable as an operator.
What about opNothing in D ;) ?

Thanks in advance,
Daniel


-- 



More information about the Digitalmars-d-bugs mailing list