Proposal to make "shared" (more) useful
Arafel
er.krali at gmail.com
Thu Sep 13 15:34:57 UTC 2018
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;
> }
> }
>
Doesn't work:
```
import std.datetime.systime;
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!SysTime t;
this() {
t = Clock.currTime;
}
}
void main() {
shared A a = new shared A;
}
```
Gives you:
onlineapp.d(6): Error: non-shared const method
std.datetime.systime.SysTime.opCast!(SysTime).opCast is not callable
using a shared mutable object
onlineapp.d(6): Consider adding shared to
std.datetime.systime.SysTime.opCast!(SysTime).opCast
onlineapp.d(8): Error: template std.datetime.systime.SysTime.opAssign
cannot deduce function from argument types !()(shared(SysTime)) shared,
candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/datetime/systime.d(612):
std.datetime.systime.SysTime.opAssign()(auto ref const(SysTime) rhs)
onlineapp.d(12): Error: template instance `onlineapp.Unshared!(SysTime)`
error instantiating
More information about the Digitalmars-d
mailing list