On Wednesday, 29 May 2013 at 13:21:21 UTC, Maxim Fomin wrote:

Fundamental issue here is that

const T t;

is almost useless, it is essentially immutable since you cannot change it and you cannot alias it. As such, it probably should be changed to a mutable object or an immutable one.

It's generic code. See the linked code and you'll see that this is not an option.

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.

Reply via email to