digitalmars.D.learn - How can I use structs in a named enum?
- simendsjo (35/35) Feb 29 2012 .. That is >> enum E : Struct {}
- simendsjo (2/37) Feb 29 2012 Hmm.. By removing ref const in opCmp, it works as expected
- simendsjo (3/49) Feb 29 2012 Btw.. Removing the ref is obvious, but why do I have to remove const?
- bearophile (4/5) Feb 29 2012 Also, and maybe here DMD has to give better error messages :-)
- simendsjo (4/9) Feb 29 2012 Yes. "Using argument types E3" doesn't make much sense when the named en...
- bearophile (4/6) Feb 29 2012 If this diagnostic bug/enhancement is not in Bugzilla then I suggest you...
- simendsjo (3/12) Feb 29 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7612
- Jonathan M Davis (3/46) Feb 29 2012 http://d.puremagic.com/issues/show_bug.cgi?id=4423
.. That is >> enum E : Struct {} struct S { int a; } // ok enum E : S { a = S(1), } // Error: need member function opCmp() for struct S to compare /* enum E2 : S { a = S(1), b = S(2) } */ struct S2 { int a; int opCmp(ref const S2 other) { return a == other.a ? 0 : (a < other.a ? -1 : 1); } } // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable using argument types (E3) // Error: cast(const(S2))S2(1) is not an lvalue // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable using argument types (E3) // Error: cast(const(S2))S2(1) is not an lvalue enum E3 : S2 { a = S2(1), b = S2(2) } void main() { } So E3 is passed as the parameter to S2.opCmp..?
Feb 29 2012
On Wed, 29 Feb 2012 12:15:35 +0100, simendsjo <simendsjo gmail.com> wrote:.. That is >> enum E : Struct {} struct S { int a; } // ok enum E : S { a = S(1), } // Error: need member function opCmp() for struct S to compare /* enum E2 : S { a = S(1), b = S(2) } */ struct S2 { int a; int opCmp(ref const S2 other) { return a == other.a ? 0 : (a < other.a ? -1 : 1); } } // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable using argument types (E3) // Error: cast(const(S2))S2(1) is not an lvalue // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable using argument types (E3) // Error: cast(const(S2))S2(1) is not an lvalue enum E3 : S2 { a = S2(1), b = S2(2) } void main() { } So E3 is passed as the parameter to S2.opCmp..?Hmm.. By removing ref const in opCmp, it works as expected
Feb 29 2012
On Wed, 29 Feb 2012 12:27:32 +0100, simendsjo <simendsjo gmail.com> wrote:On Wed, 29 Feb 2012 12:15:35 +0100, simendsjo <simendsjo gmail.com> wrote:Btw.. Removing the ref is obvious, but why do I have to remove const? Perhaps also the documentation for opCmp should be improved..?.. That is >> enum E : Struct {} struct S { int a; } // ok enum E : S { a = S(1), } // Error: need member function opCmp() for struct S to compare /* enum E2 : S { a = S(1), b = S(2) } */ struct S2 { int a; int opCmp(ref const S2 other) { return a == other.a ? 0 : (a < other.a ? -1 : 1); } } // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable using argument types (E3) // Error: cast(const(S2))S2(1) is not an lvalue // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable using argument types (E3) // Error: cast(const(S2))S2(1) is not an lvalue enum E3 : S2 { a = S2(1), b = S2(2) } void main() { } So E3 is passed as the parameter to S2.opCmp..?Hmm.. By removing ref const in opCmp, it works as expected
Feb 29 2012
simendsjo:Perhaps also the documentation for opCmp should be improved..?Also, and maybe here DMD has to give better error messages :-) Bye, bearophile
Feb 29 2012
On Wed, 29 Feb 2012 13:40:51 +0100, bearophile <bearophileHUGS lycos.com> wrote:simendsjo:Yes. "Using argument types E3" doesn't make much sense when the named enum is a complex type.Perhaps also the documentation for opCmp should be improved..?Also, and maybe here DMD has to give better error messages :-) Bye, bearophile
Feb 29 2012
simendsjo:Yes. "Using argument types E3" doesn't make much sense when the named enum is a complex type.If this diagnostic bug/enhancement is not in Bugzilla then I suggest you to add it. Now there are two persons that are quite efficient at fixing Bugzilla bugs, but they need to know there is a problem. Bye, bearophile
Feb 29 2012
On Wed, 29 Feb 2012 19:00:10 +0100, bearophile <bearophileHUGS lycos.com> wrote:simendsjo:http://d.puremagic.com/issues/show_bug.cgi?id=7612Yes. "Using argument types E3" doesn't make much sense when the named enum is a complex type.If this diagnostic bug/enhancement is not in Bugzilla then I suggest you to add it. Now there are two persons that are quite efficient at fixing Bugzilla bugs, but they need to know there is a problem. Bye, bearophile
Feb 29 2012
On Wednesday, February 29, 2012 12:15:35 simendsjo wrote:.. That is >> enum E : Struct {} struct S { int a; } // ok enum E : S { a = S(1), } // Error: need member function opCmp() for struct S to compare /* enum E2 : S { a = S(1), b = S(2) } */ struct S2 { int a; int opCmp(ref const S2 other) { return a == other.a ? 0 : (a < other.a ? -1 : 1); } } // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable using argument types (E3) // Error: cast(const(S2))S2(1) is not an lvalue // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable using argument types (E3) // Error: cast(const(S2))S2(1) is not an lvalue enum E3 : S2 { a = S2(1), b = S2(2) } void main() { } So E3 is passed as the parameter to S2.opCmp..?http://d.puremagic.com/issues/show_bug.cgi?id=4423 - Jonathan M Davis
Feb 29 2012