If I understand const right...

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 23 14:30:08 PDT 2016


On 23.03.2016 22:26, ag0aep6g wrote:
> On 23.03.2016 22:18, cy wrote:
>> On Wednesday, 23 March 2016 at 21:10:49 UTC, ag0aep6g wrote:
> [...]
>>> b = new int(*b + 1);
>> Here "b" is pointing to mutable heap allocated data, which got cast to
>> constant.
>>
>> with b = b + 1, it's still constant memory.
>
> It's stack memory. Its constness isn't any more physical than with `new`.

PS: You can also allocate an explicitly immutable int:

----
b = new immutable(int)(*b + 1);
----


More information about the Digitalmars-d-learn mailing list