Here is a working example:

import std.stdio;

class Project(Wrapped, Interface) : Interface
{
        import std.traits;
        Wrapped wrapped;

        static foreach (member; __traits(allMembers, Interface))
        {
static foreach (overload; __traits(getOverloads, Interface, member))
                {                       
mixin(`ReturnType!overload ` ~ member ~ `(Parameters!overload params) { return wrapped.` ~ member ~ `(params); }`);
                }
        }

        //this(Wrapped w)
        static Interface opCall(Wrapped w)
        {
                auto t = new typeof(this);
                t.wrapped = w;
                return t;
        }
}



interface I
{
    void foo();
}

class A
{
    void foo() { writeln("A"); }
}

class B
{
    void foo() { writeln("B"); }
}

void main()
{
        auto b = new B();
        auto a = new A();
        auto x = Project!(A, I)(a);
        auto y = Project!(B, I)(b);


        a.foo();
        b.foo();
        x.foo();
        y.foo();



}

Reply via email to