Confused about const
Paul D. Anderson
paul.d.removethis.anderson at comcast.andthis.net
Sat Mar 20 10:33:16 PDT 2010
bearophile Wrote:
> Paul D. Anderson:
>
> > After further review, I now realize that the right way (for me) to do this is to add a .dup property.<
>
> Steven Schveighoffer has given you quite good answers.
> A dup is generally not enough, because what you dup can have other immutable references nested inside. Dup is not a deep copy.
> The summary of this topic is (until inout works) that if you can return a const value, then don't copy things. This is the preferred option, because one of the main purposes of const data is to not have to copy them.
> If you can't return a const, then don't mark the input values as const. The safety given by the not deep const of Java is only partial safety.
>
> Bye,
> bearophile
You're right that dup itself can have problems with pointers/references. My struct doesn't have 2nd-level references, so dup works fine for me.
Paul
More information about the Digitalmars-d-learn
mailing list