Most basic nothrow, pure, @safe functions?

Sean Kelly sean at invisibleduck.org
Fri Mar 21 09:28:27 PDT 2014


On Friday, 21 March 2014 at 02:00:11 UTC, Walter Bright wrote:
> On 3/20/2014 6:40 PM, Steven Schveighoffer wrote:
>> How do they affect global state?
>
> Mutexes implicitly share state. It's the reason they exist. 
> They can't be pure, because pure functions don't share state.

Locking a monitor is also a mutating operation and yet I believe 
you can have const synchronized methods.  They live somewhat 
outside the normal type system.  I don't see any point in having 
pure class methods, but what about:

pure int add(T)(const(T) a, const(T) b) {
     return a + b;
}

Where the variables above are instances of a synchronized class?  
The operation would implicitly lock their monitors to perform the 
addition.


More information about the Digitalmars-d mailing list