Phobos and shared

Nick Treleaven nospam at example.net
Wed Mar 16 10:42:09 PDT 2011


On Tue, 15 Mar 2011 19:52:14 +0530, d coder wrote:

> import std.bitmanip;
> shared BitArray foo;
> void main() {
>   foo ~= true; // this does not work
>   (cast(BitArray)foo) ~= true; // Even casting does not help
> }
> 
> 
> I know that "shared" is a relatively new qualifier in D2. Are there
> plans to make Phobos "shared" compatible?

I'm certainly no expert, but it seems the cast is the problem - this 
causes an error:

auto f = cast(BitArray)foo;

shared.d(21): Error: function std.bitmanip.BitArray.opCast () is not 
callable using argument types ()
shared.d(21): Error: cannot implicitly convert expression (foo.opCast()) 
of type void[] to BitArray

Without shared, the cast is fine. It seems the problem is casting a 
shared struct instance that defines opCast (at least like 
BitArray.opCast, returning void[]).

> Are there any workarounds that I am missing.

If you're desperate, you can use __gshared instead of shared but this is 
then completely up to you to ensure no data races for foo.


More information about the Digitalmars-d mailing list