Summary: bool opEquals() for structs instead of int opEquals()
           Product: D
           Version: 2.041
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-03-15 10:23:12 PDT ---
This page:


If structs declare an opEquals member function, it should follow the following

struct S {
    int opEquals(ref const S s) { ... }

But opEquals of classes returns a boolean, so I think it's better for opEquals
of structs too to return a boolean. I think you must be sure opEquals returns a
bool. So the specs can be changed into something like:

struct S {
    bool opEquals(ref const(S) s) { ... }

Currently this code runs:

import std.c.stdio: printf;
struct Foo {
    int data;
    int opEquals(T:Foo)(T other) {
        return ==;
void main() {
    int r = Foo(5) == Foo(5);

But I think dmd has to raise a c error, and require something like:
bool opEquals(T:Foo)(ref const(Foo) other) {
bool opEquals(T:Foo)(const(Foo) other) {

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to