why can't I call const methods on shared objects?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 9 14:58:42 PDT 2014


On Fri, 09 May 2014 17:45:37 -0400, Vlad Levenfeld <vlevenfeld at gmail.com>  
wrote:

> Is there any way to declare a method as "safe regardless of  
> shared/mutability/etc" (or some other way to avoid  
> cast(Type)object.property every time I want to check a property which  
> won't affect any state)?

Not really for shared. For everything else, there's const for value  
properties, and inout for reference properties.

Shared is quite different, because the method has to be cognizant of race  
conditions. It has to be implemented differently.

Casting away shared is somewhat dangerous, but OK if you logically know  
there is no race condition.

-Steve


More information about the Digitalmars-d-learn mailing list