On Tue, 17 Apr 2012 19:51:40 -0400, H. S. Teoh <[email protected]>
wrote:
Does "tail-immutable" mean that if you strip away one layer of the type
(i.e., x[] becomes x) then the result is immutable? Or does it mean only
the *last* layer of the type is immutable?
tail immutable (and by extension tail-const) is defined as, the portion of
the type which is passed by value is mutable, while any data passed by
reference is immutable. In other words, if a type is tail-immutable,
whatever it points at is immutable, but whatever is pointing (i.e. the
head) is mutable.
Three examples:
mutable
================
int *
int[]
struct S
{
int * x;
int y;
}
immutable
================
immutable(int*)
immutable(int[])
struct SI
{
immutable(int *) x;
immutable(int) y;
}
tail-immutable
================
immutable(int) *
immutable(int)[]
struct STI
{
immutable(int) * x;
int y;
}
note that I rewrote the struct to show you what immutable(S) and a
theoretical tail-immutable(S) would do. I think this illustrates the
point better. We currently have no way of specifying STI in terms of S.
-Steve