any news on const/invariant?

Jason House jason.james.house at gmail.com
Mon Dec 17 07:08:28 PST 2007


Bill Baxter Wrote:

> James Dennett wrote:
> > Walter Bright wrote:
> >> Many C++ people have argued
> >> passionately for logical const, but I have become strongly convinced
> >> that the notion is fatally flawed.
> > 
> > How about a constant/immutable object that refers to and
> > uses (but does not contain) a mutable object?  That's rather
> > a common need, and it would be a shame not to be able to
> > declare some object as being unchanging simply because it
> > changes other objects' states, or to have to pass references
> > to those other objects in to functions instead of holding
> > them in member variables?
> 
> But the compiler needs to assume that every reference could be an owned 
> reference since it doesn't know who you consider to be the "owner".

Is it really about ownership?  That tends to imply to me that this would affect the garbage collector.

I think most posts on the topic look for exceptions to the transitive const rule.  i.e. where a pointer/class reference can point to some non-const data.  I don't fully appreciate the trouble having something like this would cause the compiler.  For parallelization of invariant objects, it seems about as bad as using a global variable.



More information about the Digitalmars-d mailing list