head const (again), but for free?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Jan 13 20:31:46 UTC 2021


On Wednesday, 13 January 2021 at 20:21:33 UTC, jmh530 wrote:
> I don't really understand the difference between head-const and 
> head-immutable.

Const allows the content to change through another reference.

Immutable does not.


So you can have one pointer that reference an object in "const 
mode", and another pointer that reference the same object in 
"mutable mode".

With immutable all pointers will reference the object in 
"immutable mode", so you can reuse any calculations you have 
derived from immutable objects with no fear of it becoming 
outdated.

However, with head-immutable the object is allowed to reference 
stuff that can be modified.

So, you could have an immutable meta-data-object that reference a 
writable-file-object. Then the meta-data-object could never 
change, so you can be certain that whatever you derive from it is 
always current.





More information about the Digitalmars-d mailing list