guidelines for parameter types
Dan
dbdavidson at yahoo.com
Tue Dec 18 10:24:56 PST 2012
On Tuesday, 18 December 2012 at 18:08:18 UTC, H. S. Teoh wrote:
>
> It's not just about whether the function mutates something or
> not.
> Sometimes the function counts on the data not changing, ever.
> For
> example, if you're implementing a library AA type, you'd want
> the key to
> be immutable so that whatever hash value you computed for the
> bucket
> will not suddenly become invalid just because the user changed
> it from
> underneath you:
>
[snip]
> In this case, the key passed to .addEntry *must* be immutable.
> That's
> the only way to guarantee that the AA's internal structures
> won't get
> invalidated by outside code.
>
Thanks! You and Ali have presented good examples where 'ref
immutable(T|V) t|v' trumps 'ref const(T|V) t|v' and if I
understand them correctly it is for whenever the instance method
(in the case of a member function) will hold onto the argument
for later use. I'll refine my selection process accordingly.
Thanks,
Dan
More information about the Digitalmars-d-learn
mailing list