On Wednesday, 29 May 2013 at 13:30:09 UTC, Jakob Ovrum wrote:
However, since const/mutable aliasing is allowed, you can do:
union U (T)
{
const T ct;
T mt;
}
because const doesn't mean that object would never change, you
can mutate it through alias. From the opposite view, there is
also no problem in reinterpeting a mutable object as const
object (since mutables can be converted to const).
Depending on your mutable indirection situation this can work
or may not.
Mutable indirection is actually not the problem with this
solution, it's the casting away of const. There's no guarantee
here that the data wasn't actually immutable when it was
created.
It is not casting away const and it has nothing to do with
immutable, also this does not suffer from data was actually
immutable problem.