Does D have object wrappers for primitives?

Cauterite via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 30 00:11:37 PDT 2016


On Saturday, 30 July 2016 at 04:12:45 UTC, stunaep wrote:

> Thank you. This is just what I needed. I am curious though as 
> to why this doesn't work with strings. It would work if I 
> removed immutable from the Boxed constructor but I thought 
> strings were immutable. I get a compiler error 'not callable 
> using a mutable object'. Even marking a string with the 
> immutable keyword has the same result.

auto s = new immutable(Boxed!string)(`foo`);

what it's saying is that the box itself needs to be immutable.
Honestly I don't know why it was even possible to make a mutable 
box in the first place, when the only constructor is marked 
`immutable`.


More information about the Digitalmars-d-learn mailing list