D safety! New Feature?
Mark J Twain via Digitalmars-d
digitalmars-d at puremagic.com
Tue Aug 2 15:13:47 PDT 2016
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.
More information about the Digitalmars-d
mailing list