What's wrong in this templatized operator overload ?

Cauterite via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 21 22:17:28 PDT 2015


On Thursday, 22 October 2015 at 04:25:01 UTC, MobPassenger wrote:
> On Thursday, 22 October 2015 at 04:01:16 UTC, Mike Parker wrote:
>> On Thursday, 22 October 2015 at 03:19:49 UTC, MobPassenger 
>> wrote:
>>> code:
>>> ---
>>> struct Foo
>>> {
>>>     bool opIn_r(T)(T t){return false;}
>>> }
>>>
>>
>> This needs to be marked with const:
>>
>> struct Foo
>> {
>>     bool opIn_r(T)(T t) const {return false;}
>> }
>
> what's the rationale ? what's guaranteed by the qualifier 
> that's not already true without const ?

`const` just means the function won't mutate the object. `const` 
functions can be safely called on mutable, const and immutable 
objects. Non-`const` functions can only be called on mutable 
objects.


More information about the Digitalmars-d-learn mailing list