www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24039] New: Provide operator overload members for built-in

https://issues.dlang.org/show_bug.cgi?id=24039

          Issue ID: 24039
           Summary: Provide operator overload members for built-in types
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: qs.il.paperinik gmail.com

For user-defined types, if `a + b` works, it’s because `typeof(a)` has
`opBinary` and `a.opBinary!"+"(b)` compiles, or `typeof(b)` has `opBinaryRight`
and `b.opBinaryRight!"+"(a)` compiles. (If both are present, it seems 
`opBinaryRight` is preferred.

If both are built-in types, there are no `opBinary` or `opBinaryRight`, as well
as other operators such as `opEquals` and `opCmp`.

It would make meta-programming a lot easier if one wouldn’t have special-case
built-in types and those operator (member) functions would Just Work.

For some cases, they could even be defined in object.d as free functions, but
it would be ideal if the compiler just pretended that those types had the
operator member functions.

--
Jul 07 2023