On Friday, 9 May 2014 at 21:58:41 UTC, Steven Schveighoffer wrote:
On Fri, 09 May 2014 17:45:37 -0400, Vlad Levenfeld
<vlevenf...@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
You could just declare the function as "immutable".
But then, it'll only work on immutable types.
But then again, that would be the only way to actually statically
and safely guarantee there are no race conditions.