Immutability and other attributes, please review

Jonathan M Davis jmdavisProg at gmx.com
Thu Jun 14 08:20:08 PDT 2012


On Thursday, June 14, 2012 15:53:45 Roman D. Boiko wrote:
> On Thursday, 14 June 2012 at 13:33:43 UTC, Roman D. Boiko wrote:
> > On Thursday, 14 June 2012 at 13:31:01 UTC, Roman D. Boiko wrote:
> >> On Thursday, 14 June 2012 at 13:21:34 UTC, Jacob Carlborg
> >> 
> >> wrote:
> >>> If you want that and have it immutable you need to make a
> >>> deep copy of the passed in object to be safe. You could use
> >>> const instead and also making the argument const. If an
> >>> argument is const you can pass both mutable and immutable
> >>> values, and const of course.
> >> 
> >> Thanks, I'll try that.
> > 
> > But then I will have problems sharing such data structures with
> > different threads, correct?
> 
> Convenience of usage would be less important than compiler
> guarantees, so it looks like I have to stick to immutable, not
> const.

Well, if you break the compiler guarantees, then your program will not work 
properly. const and immutable need to be used in such a way that you do not 
break the compiler's guarantees. If you're having to cast with const or 
immutable, then you're probably doing something wrong.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list