On Monday, 21 December 2015 at 09:06:08 UTC, Shriramana Sharma wrote:
http://dlang.org/spec/template.html#TemplateTupleParameter

Apart from the obvious need for changing the references to tuples to alias sequences (for which I'm working on a PR), my question:

Both the above page and http://dlang.org/phobos/std_meta.html refer to "slicing" alias sequences. In D slicing means just creating another reference to the same memory as the sliced object.

Given that AliasSeq-s cannot be written to[*], it's not possible for me to test whether it's actually sliced or a new AliasSeq with the same elements is created. Otherwise I could do something like this:

alias A = [int, 2, symbol];
alias B = A[1 .. $];
alias C = A[0 .. $ - 1];
A[1] = 3; // not possible
static assert(B[0] == 3 && C[1] == 3);

So out of curiosity I'd like to know how this is implemented in the compiler: as really a slice or a copy? (Posting this to D and not learn since it relates to compiler internals.)

I don't know the answer, but I suspect it's a (shallow) copy. Anyway, as you've noticed, there's no observable difference either way, so this is an implementation detail which the documentation shouldn't mention (if this was the intention behind your question).

Reply via email to