Let's not make invariants const

Era Scarecrow rtcvb32 at yahoo.com
Sat Aug 4 00:46:42 PDT 2012


On Saturday, 4 August 2012 at 07:15:50 UTC, Jonathan M Davis 
wrote:
> The problem is that if the this pointer/reference is const, 
> then you can't call any member functions which aren't const, 
> and you can't call any non-const functions on any member 
> variables, because _they're_ const, because the this 
> pointer/reference is const. And there are plenty of types out 
> there which _can't_ have many of their member functions be 
> const and do what they need to do, because D's const is both 
> physical and transitive (unlike C++'s const). So, it's quite 
> easy to get into a situation, where you can't call much of any 
> functions at all if the this pointer/reference is const even 
> though calling the non-const functions wouldn't actually mutate 
> anything.

  Data-wise I see it both as a problem, and not as a problem. so 
contracts and invariants and debug statements should have the 
@safe, pure, and const nature stripped for debugging support.

  I would think it does however during verbose output specifying 
if an invariant or contract is changing data and that may alter 
behavior.


More information about the Digitalmars-d mailing list