Possible way to achieve lazy loading with const objects

Christophe travert at phare.normalesup.org
Fri Sep 30 06:39:42 PDT 2011


"Steven Schveighoffer" , dans le message (digitalmars.D:145812), a écrit :
> What we are discussing is why opEquals should not be const, not why all  
> functions should not be const.

Considering the viral behavior of const in D, we are discussing why all 
function callable from opEqual should be declared const, even if the 
programmer do not want to use const at all (but obviously want to use 
opEqual.

> My opinion is:
> 
> 1. we need const opEquals.  There is no debate on this I think.
> 2. The compromise solution is not worth the gain.  I'd rather have most of  
> my objects compare as quickly as possible.
> 3. It should be possible to create a mutable opEquals and have it hook  
> with obj == obj.  This is different than the compromise solution, which  
> puts both const and non-const opEquals in Object.  This means we need to  
> reengineer how the compiler does opEquals for objects.
> 4. Yes, it is worth breaking existing compilation to switch to const  
> opEquals in Object.

I think I agree with you, except perhaps on point 4. Can you ellaborate 
point 3 ? I am not sure I understand. Do you talk about hooking obj == 
obj2 to a mutable opEqual only when obj and obj2 are mutable _and_ 
define a mutable opEqual, instead of calling mutable opEqual directly, 
and having it forward to const opEqual at the cost of one extra virtual 
call ?

-- 
Christophe



More information about the Digitalmars-d mailing list