On Sunday, October 19, 2014 22:33:32 Dmitry Olshansky via Digitalmars-d wrote: > 17-Oct-2014 16:42, Marco Leise пишет: > > Am Fri, 17 Oct 2014 00:42:24 +0000 > > schrieb "IgorStepanov" <[email protected]>: > > > > OK, I've run into the same problem and there is no line > > number, just: > > > > Error: immutable method Lib.Sys.File.File.~this is not callable using a > > mutable object Error: mutable method Lib.Sys.File.File.~this is not > > callable using a immutable object > > > > haha! I should start from scratch. > > Been there. Which implies that we can't have ref-counted const object > (or ref-count has to leave outside of immutable section).
Yeah. Ref-counting and const do not mix in D. The ref-counting would violate const unless it's in a wrapper object or in a table somewhere. The wrapper fails as soon as it ends up being const (either directly or because it's inside of another object that's been marked const). And having a table somewhere outside the object or any wrapper makes it so that it doesn't work with pure. There are some serious, practical downsides to transitive, physical const like D has. And I don't think that any of us really know yet where the line is between where const should and shouldn't be used. Too often, the solution is to use it everywhere or to use it nowhere. And some folks violate it and try and make it more like logical const (e.g. as I understand it, vibe.d does ref-counting with const objects by casting away const and then mutating the ref-count, which is definitely a risky thing to be doing and arguably should never be done - but with the strong restrictions of D's const, it's exactly the sort of thing that people are going to be tempted to do). - Jonathan m Davis
