digitalmars.D - Request: traits isImplemented
- JS (14/14) Jul 05 2013 I have a request to add to __traits to check if a method/property
- Jacob Carlborg (5/19) Jul 05 2013 derivedMembers perhaps:
- JS (4/32) Jul 05 2013 This doesn't work with overloaded members. It's possible that a
- Jacob Carlborg (4/7) Jul 05 2013 There's a trait for that as well. Read the documentation.
- JS (3/10) Jul 05 2013 Thanks for being so helpful... I bet you know exactly where it is
- Jacob Carlborg (4/6) Jul 06 2013 http://dlang.org/traits.html#getOverloads
- Andrej Mitrovic (3/10) Jul 05 2013 Perhaps looking at the BlackHole or WhiteHole implementation can help
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (18/32) Jul 05 2013 Can you make A a class with default myfunc() implementation?
I have a request to add to __traits to check if a method/property of a class/struct is actually implemented or not. interface A { void myfunc(); } class B : A { } // myfunc not implemented class C : A { void myfunc() { ... } // myfunc implemented This may seem odd but I need it for conditional mixin compilation to add in the methods when they are not implemented. A sort of default proxy, wrapper, or composite pattern implementer. It reduces boilerplate code significantly. Unfortunately allMembers returns methods that are not actually implemented or part of the class. Something like allImmediateMembers would be useful where it only returns the actually explicit members of the immediate class/struct that it is used on and accomplish the same task.
Jul 05 2013
On 2013-07-05 11:52, JS wrote:I have a request to add to __traits to check if a method/property of a class/struct is actually implemented or not. interface A { void myfunc(); } class B : A { } // myfunc not implemented class C : A { void myfunc() { ... } // myfunc implemented This may seem odd but I need it for conditional mixin compilation to add in the methods when they are not implemented. A sort of default proxy, wrapper, or composite pattern implementer. It reduces boilerplate code significantly. Unfortunately allMembers returns methods that are not actually implemented or part of the class. Something like allImmediateMembers would be useful where it only returns the actually explicit members of the immediate class/struct that it is used on and accomplish the same task.derivedMembers perhaps: http://dlang.org/traits.html#derivedMembers -- /Jacob Carlborg
Jul 05 2013
On Friday, 5 July 2013 at 10:55:26 UTC, Jacob Carlborg wrote:On 2013-07-05 11:52, JS wrote:This doesn't work with overloaded members. It's possible that a function with the same name may be completely unrelated to the interface being implemented.I have a request to add to __traits to check if a method/property of a class/struct is actually implemented or not. interface A { void myfunc(); } class B : A { } // myfunc not implemented class C : A { void myfunc() { ... } // myfunc implemented This may seem odd but I need it for conditional mixin compilation to add in the methods when they are not implemented. A sort of default proxy, wrapper, or composite pattern implementer. It reduces boilerplate code significantly. Unfortunately allMembers returns methods that are not actually implemented or part of the class. Something like allImmediateMembers would be useful where it only returns the actually explicit members of the immediate class/struct that it is used on and accomplish the same task.derivedMembers perhaps: http://dlang.org/traits.html#derivedMembers
Jul 05 2013
On Friday, 5 July 2013 at 14:59:19 UTC, JS wrote:This doesn't work with overloaded members. It's possible that a function with the same name may be completely unrelated to the interface being implemented.There's a trait for that as well. Read the documentation. -- /Jacob Carlborg
Jul 05 2013
On Friday, 5 July 2013 at 16:04:19 UTC, Jacob Carlborg wrote:On Friday, 5 July 2013 at 14:59:19 UTC, JS wrote:Thanks for being so helpful... I bet you know exactly where it is at and that it does exactly what I need! You're so smart!This doesn't work with overloaded members. It's possible that a function with the same name may be completely unrelated to the interface being implemented.There's a trait for that as well. Read the documentation. -- /Jacob Carlborg
Jul 05 2013
On 2013-07-05 19:44, JS wrote:Thanks for being so helpful... I bet you know exactly where it is at and that it does exactly what I need! You're so smart!http://dlang.org/traits.html#getOverloads -- /Jacob Carlborg
Jul 06 2013
On 7/5/13, JS <js.mdnq gmail.com> wrote:I have a request to add to __traits to check if a method/property of a class/struct is actually implemented or not. interface A { void myfunc(); } class B : A { } // myfunc not implemented class C : A { void myfunc() { ... } // myfunc implemented This may seem odd but I need it for conditional mixin compilation to add in the methods when they are not implemented.Perhaps looking at the BlackHole or WhiteHole implementation can help you out to implement this via a template? They're in std.typecons.
Jul 05 2013
On 07/05/2013 02:52 AM, JS wrote:I have a request to add to __traits to check if a method/property of a class/struct is actually implemented or not. interface A { void myfunc(); } class B : A { } // myfunc not implemented class C : A { void myfunc() { ... } // myfunc implemented This may seem odd but I need it for conditional mixin compilation to add in the methods when they are not implemented. A sort of default proxy, wrapper, or composite pattern implementer. It reduces boilerplate code significantly. Unfortunately allMembers returns methods that are not actually implemented or part of the class. Something like allImmediateMembers would be useful where it only returns the actually explicit members of the immediate class/struct that it is used on and accomplish the same task.Can you make A a class with default myfunc() implementation? class A { void myfunc() { writeln("default myfunc"); } } class B : A { } class C : A { override void myfunc() { writeln("C.myfunc"); } } Or, you can leave A as an interface and insert another class after it that has the default implementation: A | ADefaults | | B C Ali
Jul 05 2013