Making array elements truly const/immutable
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Thu Aug 2 04:34:15 PDT 2012
On 02/08/12 10:22, Era Scarecrow wrote:
> If someone wants to modify something, they can go into assembly language and
> force it or use C wrappers that lie wouldn't stop it. Comes down to the
> programmers in the end.
That's a very good point. I'm not asking for something rock-solid, but just
whether there's something I can declare that the compiler will pick up on in the
usual case.
Though actually, I'm warming to the possibility to un-const an array via a cast;
it would be something to use very cautiously, but potentially useful in places.
> It almost sounds like you'd want const access with COW-like properties
> (copy-on-write), so if you try to make changes it duplicates it and uses the
> duplicate afterwards. I began a test for COW arrays before, but haven't finished
> it.
Pretty much; but I think Ali's notes on std.conv.to have probably provided me
with the real toolset I need.
Thanks very much for the advice!
More information about the Digitalmars-d-learn
mailing list