mutable, const, immutable guidelines
qznc
qznc at web.de
Thu Oct 10 16:12:23 PDT 2013
On Thursday, 10 October 2013 at 18:39:32 UTC, Christian Köstlin
wrote:
> On 10/10/13 1:05 , qznc wrote:
> Very interesting discussion!
>
> > contract between caller and callee. If an argument is const,
> it means
> > the callee says he can handle others changing the state
> concurrently.
> i think what the usual understanding of const for an argument
> to callee is, what is written at http://dlang.org/const3.html.
> that means for me, that callee promises not to change the data
> itself. perhaps a bettr description would be readonly.
The linked page clearly says "It may, however, be changed by
another reference to that same data."
> usually you would think that no one else should change the data
> while callee runs. but at least with c++ i could imagine
> running callee in a thread with a reference to a const thing
> which changes underneath and while callee is running.
A const argument gives information to both sides. For the caller
it means callee does not modify the data. For the callee it means
somebody else (another thread) may modify the data at any time.
An immutable argument means the same for the caller, but gives an
additional guarantee to the callee that nobody modifies the data.
More information about the Digitalmars-d-learn
mailing list