C++ mutable in D
Alexandru Ermicioi
alexandru.ermicioi at gmail.com
Sun Aug 1 19:42:24 UTC 2021
On Friday, 30 July 2021 at 19:17:55 UTC, Michael Galuza wrote:
> Is there any analogue of C++ `mutable` in D? As far as I
> understand, this is impossible due to transitive constness, but
> maybe some variation of `Rebindable` will be useful?
>
> P.S. Of course I mean 'fair' mutable, not qualifier-away
> `cast()`.
Not possible as other people mentioned. In this case the best
approach would be to either design your struct to contain const
and mutable fields, and design it's interface accordingly, or you
could make a mutable decorator that would be mutable and expose
mutable aspects, while keeping the decorated instance const.
Best regards,
Alexandru.
More information about the Digitalmars-d
mailing list