Code duplication where you wish to have a routine called with either immutable or mutable arguments
Paul Backus
snarwin at gmail.com
Tue May 30 04:02:22 UTC 2023
On Tuesday, 30 May 2023 at 02:57:52 UTC, Cecil Ward wrote:
> I have often come into difficulties where I wish to have one
> routine that can be called with either immutable or (possibly)
> mutable argument values. The argument(s) in question are in,
> readonly, passed by value or passed by const reference. Anyway,
> no one is trying to write to the items passed in as args, no
> badness attempted.
>
> When I call the routine from one place with an argument that is
> immutable and then from another that is not, or it could be
> const as well, or not, that’s when I get all kinds of type
> mismatch errors. And I certainly don’t want to pour cast-like
> type conversion operations over all the place at these problem
> occurrences. it’s surely asking for problems.
Normally you would use const for this, since a const parameter
can accept either a mutable or an immutable argument. If const
isn't working for you, then there's probably something else going
on that you haven't mentioned. Can you post an example of the
kind of code that gives you these errors?
More information about the Digitalmars-d-learn
mailing list