Associative Array of Const Objects?

bitwise via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 29 11:58:38 PDT 2015


> perhaps something like Rebindable could be used.

Looking at Rebindable now, there is a useful example. There 
should probably be a mention of this on the const/immutable docs. 
For people coming from C++, this will not be obvious.

auto a = Rebindable!(const Widget)(new Widget);
a.y();          // fine
a.x = 5;        // error! can't modify const a
a = new Widget; // fine

Given the above example though, I have to say it's ridiculously 
verbose and I much prefer the C++ way. I have never used 
read-only-const in C++, nor would I, and it's really annoying 
that it's forced on D programmers. I can see the benefit of 
protecting the underlaying data, but not the pointer/reference 
itself.

I'm assuming a DIP for this would be futile at best =/

Thanks


More information about the Digitalmars-d-learn mailing list