[Issue 3967] New: bool opEquals() for structs instead of int opEquals()
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 15 10:23:13 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3967
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
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-03-15 10:23:12 PDT ---
This page:
http://www.digitalmars.com/d/2.0/operatoroverloading.html
Contains:
If structs declare an opEquals member function, it should follow the following
form:
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) {
printf("A");
return this.data == other.data;
}
}
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) {
Or:
bool opEquals(T:Foo)(const(Foo) other) {
etc.
--
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