.idup flawed?
Xinok
xnknet at gmail.com
Thu Jun 21 04:21:26 PDT 2007
.idup creates an invariant copy of an array. According to this page:
http://digitalmars.com/d/const.html
"One is that constant data really is constant. It never changes. It's
different enough that it needs a different name. In D, this kind of
constant is called an invariant."
So if you have an invariant array, you expect that it's data will never
change.
This is not always the case if you have an array of classes. Classes are
pointers, and when you use the .idup property, it only creates invariant
copies of the pointers, and not the objects themselves. This means that
the objects are still mutable and the data can change, which is not the
intended behavior of invariant.
More information about the Digitalmars-d
mailing list