Const/immutable
in aias
Const vs Immutable
Const:
Cannot be changed by the const reference to the data, but can be changed by another reference.
int i = 8;
const(int*) ip = &i;
i = 7; //OK, but *ip == 7
*ip = 9; //error
Immutable:
Cannot be changed and no other references can change it.
immutable int i = 8; //can never be changed
immutable(int*) ip = &i; //pointer and contents can't be changed
immutable Dimensions
By default dimensions are mutable:
auto dim = dimension!"Test"(...); //mutable
Once dimensions are added to a cube they become immutable:
auto cube = denseCube!double(dim);
auto cubeDim = cube.getDimension!"Test"; //immutable
Dimensions can be made immutable outside of a cube:
auto iDim = dim.assumeDimUnique;
A set of dimensions can be made immutable:
auto iDims = enforceUnique(dim1, dim2).expand;
const/immutable cubes
Cubes are mutable by default:
auto cube = denseCube!double(...); //mutable
They can be made constant easily:
But this isn't the same as immutable!
const cCube = denseCube!double(...);
Like dims, cubes can be made immutable:
auto iCube = cube.assumeCubeUnique;
Cube.assumeCubeUnique invalidates the passed cube:
auto range = cube[]; //segfault!
auto range = iCube[]; //The world is good!
Questions?
aias_const
By Jonathan Crapuchettes
aias_const
- 809