Synchronized Classes and Struct Members

Timon Gehr timon.gehr at gmx.ch
Tue Oct 25 09:59:53 PDT 2011


On 10/25/2011 06:24 PM, Andrew Wiley wrote:
>
>
> On Tue, Oct 25, 2011 at 8:06 AM, Gor Gyolchanyan
> <gor.f.gyolchanyan at gmail.com <mailto:gor.f.gyolchanyan at gmail.com>> wrote:
>
>     And so you can have both thread-safe synchronized heavy-duty container
>     and a fast and small container all in one just by overloading the
>     appropriate methods and adding appropriate synchronization blocks in
>     the shared ones.
>     This is one of those "little" advantages of D over C++, that make my
>     life _SO_ much easier.
>
>
> Except that overloading shared and non-shared methods is not allowed.

Yes it is.

struct X{
     string foo(){ return "unshared"; }
     string foo()shared{ return "shared"; }
}

void main(){
     X x;
     shared X y;
     assert(x.foo() == "unshared");
     assert(y.foo() == "shared");
}


More information about the Digitalmars-d mailing list