www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - overriding alias symbols

reply Superstar64 <Hexagonalstar64 gmail.com> writes:
I'm trying to use mixin templetes to provide generic default 
implementations.
Something like this:
---
abstract class MyAbstractClass
{
     void myAbstractMethod();
}

mixin template defaultImplentation(alias Method, T...)
{
     override void Method()
     {
     }
}

class MyClass : MyAbstractClass
{
     mixin defaultImplentation!(myAbstractMethod);
}
---
Anyone have any ideas?
Oct 12 2016
next sibling parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Wednesday, 12 October 2016 at 22:14:32 UTC, Superstar64 wrote:
 I'm trying to use mixin templetes to provide generic default 
 implementations.
 Something like this:
 ---
 abstract class MyAbstractClass
 {
     void myAbstractMethod();
 }

 mixin template defaultImplentation(alias Method, T...)
 {
     override void Method()
     {
     }
 }

 class MyClass : MyAbstractClass
 {
     mixin defaultImplentation!(myAbstractMethod);
 }
 ---
 Anyone have any ideas?
override void mixin (__traits(identifier, Method)) ... ?
Oct 12 2016
parent Superstar64 <Hexagonalstar64 gmail.com> writes:
On Wednesday, 12 October 2016 at 22:46:14 UTC, Stefan Koch wrote:
 override void mixin (__traits(identifier, Method)) ...  ?
Doesn't work: test.d(8): Error: no identifier for declarator void test.d(9): Error: found '{' when expecting ')' test.d(10): Error: found '}' when expecting ';' I could make the whole function a mixin but I don't wanna hurt my compile times.
Oct 12 2016
prev sibling parent Superstar64 <Hexagonalstar64 gmail.com> writes:
On Wednesday, 12 October 2016 at 22:14:32 UTC, Superstar64 wrote:
 ...
Nevermind I just realized I can do this: --- abstract class MyAbstractClass { void myAbstractMethod(); } void defaultImplentation(T...) { } class MyClass : MyAbstractClass { override void myAbstractMethod() { return defaultImplentation!(); } }
Oct 12 2016