digitalmars.D.learn - How to determine if a function is implemented
- JS (30/30) Jul 04 2013 the code
- Kenji Hara (24/54) Jul 04 2013 It's completely unnecessary. A mixed-in function cannot override
the code http://dpaste.dzfl.pl/25bfeeb7 attempts to implement an interface. The current issue is that I need to determine if the user has added the member of the interface to the class or if the mixin needs to add it. so the lines class B : A { A a; //void myfunc(float a, int b, string c) { }; // property int myvalue() { return 4; } mixin implementInterface!a; } The mixin adds the two commented functions above it which effectively implement the interface A in B. The problem is, I might want to manually specify one, e.g., class B : A { A a; void myfunc(float a, int b, string c) { }; // property int myvalue() { return 4; } mixin implementInterface!a; } So the mixin needs to be aware and not add a method that is already implemented. I need some way for the mixin to distinguish the two cases above. e.g., isImplemented!(myfunc(float, int, string)) or something like that.
Jul 04 2013
On Friday, 5 July 2013 at 01:27:06 UTC, JS wrote:the code http://dpaste.dzfl.pl/25bfeeb7 attempts to implement an interface. The current issue is that I need to determine if the user has added the member of the interface to the class or if the mixin needs to add it. so the lines class B : A { A a; //void myfunc(float a, int b, string c) { }; // property int myvalue() { return 4; } mixin implementInterface!a; } The mixin adds the two commented functions above it which effectively implement the interface A in B. The problem is, I might want to manually specify one, e.g., class B : A { A a; void myfunc(float a, int b, string c) { }; // property int myvalue() { return 4; } mixin implementInterface!a; } So the mixin needs to be aware and not add a method that is already implemented. I need some way for the mixin to distinguish the two cases above. e.g., isImplemented!(myfunc(float, int, string)) or something like that.It's completely unnecessary. A mixed-in function cannot override properly declared function that has same name in the mixed-in scope. interface I { int foo(); } mixin template Foo() { override int foo() { return 1; } } class C1 : I { mixin Foo!(); } class C2 : I { int foo() { return 10; } mixin Foo!(); // mixed-in foo is not stored in vtbl } void main() { assert(new C1().foo() == 1); assert(new C2().foo() == 10); } Kenji Hara
Jul 04 2013
class C2 : I { int foo() { return 10; } mixin Foo!(); // mixed-in foo is not stored in vtbl }In this case maybe should be error thrown? Or where is mixed function?
Jul 05 2013
On Friday, 5 July 2013 at 06:34:58 UTC, Kenji Hara wrote:On Friday, 5 July 2013 at 01:27:06 UTC, JS wrote:Cool, now that you've pointed that out I do remember reading that. The code was working all along, the issue being d-ide saying that build failed and not producing a binary. I guess this solves that problem and I better implement the code.the code http://dpaste.dzfl.pl/25bfeeb7 attempts to implement an interface. The current issue is that I need to determine if the user has added the member of the interface to the class or if the mixin needs to add it. so the lines class B : A { A a; //void myfunc(float a, int b, string c) { }; // property int myvalue() { return 4; } mixin implementInterface!a; } The mixin adds the two commented functions above it which effectively implement the interface A in B. The problem is, I might want to manually specify one, e.g., class B : A { A a; void myfunc(float a, int b, string c) { }; // property int myvalue() { return 4; } mixin implementInterface!a; } So the mixin needs to be aware and not add a method that is already implemented. I need some way for the mixin to distinguish the two cases above. e.g., isImplemented!(myfunc(float, int, string)) or something like that.It's completely unnecessary. A mixed-in function cannot override properly declared function that has same name in the mixed-in scope. interface I { int foo(); } mixin template Foo() { override int foo() { return 1; } } class C1 : I { mixin Foo!(); } class C2 : I { int foo() { return 10; } mixin Foo!(); // mixed-in foo is not stored in vtbl } void main() { assert(new C1().foo() == 1); assert(new C2().foo() == 10); } Kenji Hara
Jul 05 2013