On 09/13/2018 05:16 PM, Kagamin wrote:
struct Unshared(T)
{
     private T value;
     T get() shared { return cast(T)value; }
     alias get this;
     void opAssign(T v) shared { value=cast(shared)v; }
}

shared synchronized class A
{
     private Unshared!(int[]) a;
     int[] f()
     {
         return a;
     }
}


My current attempt, still work in progress:


```
import std.stdio;
import std.datetime.systime;

shared struct GShared(T) {
        ubyte[T.sizeof] payload;

    this(T t) {
                *(cast(T*) &payload) = t;
        }
    this(shared T t) {
                *(cast(T*) &payload) = cast() t;
        }
        void opAssign(T t) {
                *(cast(T*) &payload) = t;
        }
        void opAssign(shared T t) {
                *(cast(T*) &payload) = cast() t;
        }
    ref T data() {
        return *(cast(T*) &payload);
    }
    alias data this;
}

shared synchronized class A {
    this() {
            t = Clock.currTime;
    }

    void printIt() {
        writeln(t);
    }

    private:
    GShared!SysTime t;
}

void main() {
    shared A a = new shared A;
    a.printIt;
}
```

Reply via email to