Inherited const when you need to mutate

Jonathan M Davis jmdavisProg at gmx.com
Mon Jul 9 11:54:55 PDT 2012


On Monday, July 09, 2012 11:53:05 H. S. Teoh wrote:
> I'm wondering if it makes any sense to have _also_ have non-const
> versions of things like toString, for objects that want to implement
> caching. So in contexts where const is not important, you can have
> caching, network access, whatever you want, but for core language stuff
> that needs to assume const, everything will still work (just a little
> slower).

That works as long as the const version still works. As soon as you _need_ to 
mutate in order to do opEquals, opCmp, toString, or toHash (as can happen with 
lazy loading schemes), it doesn't work. Basic caching should work with that 
though.

- Jonathan M Davis


More information about the Digitalmars-d mailing list