Is it possible to elegantly craft a class that can be used as shared and as normal?

Gary Willoughby dev at nomad.so
Sun Mar 2 09:54:00 PST 2014


Is it possible to elegantly craft a class that can be used as 
shared and as normal?

I have a class which functions fine when instantiated as normal 
but i want to enable it for use for shared objects.

     auto t = T();
     auto t = shared(T)();  //<--- like this.

Then i have the problem that a shared object can not call non 
shared methods. The only solution i can see is to have multiple 
overloads of the class' methods to handle being shared, like this:

class T
{
     public void Foo() {...}
     public shared void Foo() {...}
}

Is this the right way of going about this? The reason i ask is 
that both methods have exactly the same code and to avoid 
duplication i'm using mixins for each method body, yuk! help?


More information about the Digitalmars-d-learn mailing list