if(bool = x) does not give a boolean result

Steven Schveighoffer schveiguy at yahoo.com
Fri May 7 05:07:36 PDT 2010


On Fri, 07 May 2010 08:02:00 -0400, Graham Fawcett <fawcett at uwindsor.ca>  
wrote:

> On Fri, 07 May 2010 07:56:23 -0400, Steven Schveighoffer wrote:
>
>> I have code like this in dcollections:
>>
>>
>>      /**
>>       * Removes the element that has the given key.  Sets wasRemoved to
>> true if the
>>       * element was present and was removed. *
>>       * Runs on average in O(1) time.
>>       */
>>      HashMap remove(K key, out bool wasRemoved) {
>>          cursor it = elemAt(key);
>>          if(wasRemoved = !it.empty)
>>          {
>>              remove(it);
>>          }
>>          return this;
>>      }
>>
>>
>> However, this does not compile with the following message:
>>
>> dcollections/HashMap.d(561): Error: '=' does not give a boolean result
>>
>> line 561 is the if statement.
>>
>> Since when did bool = bool not give a bool result?
>
> Don't you mean bool == bool, not bool = bool?

No.  I meant bool = bool.  I'm not comparing two bools, I'm assigning to a  
bool, and then using if on the result.  At best, this is a bogus error  
message.

-Steve


More information about the Digitalmars-d-learn mailing list