On Thursday, 19 May 2016 at 20:44:54 UTC, ciechowoj wrote:
Is there D equivalent of C++'s mutable keyword? Like the one that allows to modify a field of struct from constant method. Or some alternative solution?

A little personal experience. I wrote a tool that had certain flags that did things turned on by default, and turning them off using other flags. This seemed the best choice at the time, but upon later reflection it's hard to remember details you'd not think about unless you wanted them active. Think about a simple action like 'get home', which you also have to 'turn sink off, don't change bedding, don't shave, don't walk dog' because otherwise you have to do all those when all you planned when getting home was taking a shower and going to bed. Remembering to add all the flags/changes/options for the utility quickly was becoming a pain, to which I reverted my options to only be on when called/intended them rather than thinking them on by default was the best option.

As for mutable. It's mutable unless you specify otherwise, and the whole object as a whole can be immutable/const; Don't complicate the rules so "it's const (except when it's not)" logic, either make it intentionally const/immutable or don't.

Reply via email to