On Monday, 1 October 2018 at 08:04:38 UTC, Kagamin wrote:
Shared data may need different algorithms.
Yes, but those same algorithms will work on unshared (they might
be slower but they will work). The reverse is not true, it can
lead to race conditions.
If unshared data is
implicitly convertible to shared, you start to conflate shared
data with unshared, so you're back to C-style sharing.
No, when participating in overloading, an unshared method will be
preferred over a shared method for an unshared object. Same with
parameters that are not `this`.
This is how you can do it:
shared struct SharedBob
{
this(int){}
void setThing(){}
}
alias shared SharedBob Bob;
void f(ref shared Bob a, ref Bob b)
{
a.setThing(); // I have a shared object, can call shared
method
b.setThing(); // ok
}
int main()
{
auto b=Bob(0);
Bob c;
f(b,c);
return 0;
}
I'm not sure what that was supposed to demonstrate.