On Tuesday, 2 August 2016 at 21:48:58 UTC, Mark Twain wrote:
[...]

Another useful feature I forgot to mention is that we can cast between Immutable and Muttable types.

class ImmutableTest
{
    private MutableArray!int data;
    public ImmutableArray!int Data;

    this()
    {
        // Creates a view to data, but Data cannot modify data.
        Data.View(data);
    }

    public Add(int x)
    {
        data.Add(x);
    }
}

Data can then be exposed without worrying about it getting trampled on. Sense a MutableArray contains all the functionality of an ImmutableArray, there should be no problems with the interpretation.

Reply via email to