Most basic nothrow, pure, @safe functions?

Walter Bright newshound2 at digitalmars.com
Fri Mar 21 11:21:02 PDT 2014


On 3/21/2014 9:28 AM, Sean Kelly wrote:
> 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.

Yes, I think the pairing of lock/unlock of a mutex can be pure, but just a lock 
or just an unlock cannot be.


More information about the Digitalmars-d mailing list