Bypassing const with a union

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Jun 1 16:14:08 PDT 2012


On 02.06.2012 0:24, Era Scarecrow wrote:
> While working on the BitArray I've come across an interesting dilemma,
> which is both bad and good. Let's take the following

[snip]

> Thinking about it, although this is possible you might still allow it
> but send warnings when the compiler detects it. Reason? Const takes
> effect too soon, sometimes before you can finish working on the changes.
> I've tried moving them to a new constructor(s) but keep having issues
> when the inputs are const as the struct assumes it's starting non-const.
> I think...
>

There is also cast() that just cancels out all const/shared/immutable.

> Breaking the const system while your still building/preparing the new
> object should be allowed (as with the slice example)

Yes in constructor. Or by constructing incrementally a mutable object, 
inside pure function e.g. compiler can convert to immutable on return 
(auto-magically).

  but once you pass
> it out it shouldn't be allowed anymore.


-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list