On Wednesday, 20 February 2013 at 08:25:45 UTC, Jakob Ovrum wrote:
On Wednesday, 20 February 2013 at 06:00:02 UTC, deadalnix wrote:
As discussed previously, I really wonder hy a const and non
const version of a function can exists in a first place. What
problem does it solve that isn't better solved by inout ?
I use overloading of const/immutable in one of my projects to
avoid a string copy when possible:
https://github.com/JakobOvrum/Dirk/blob/master/irc/client.d#L332
Granted, here const does not apply to the implicit `this`
parameter, but it is essentially the same thing.
Yes I know that usage. That is different for this, because of
overload problems. For parameter that isn't really an issue.
As of you case specifically, I wouldn't do that, because you have
no gain in duplicating the string in the function rather than
before passing it. I however don't deny that this may be useful
in some cases. It cause quite a lot of trouble with overloads.