On Monday, 21 December 2015 at 09:06:08 UTC, Shriramana Sharma wrote:
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.

AliasSeqs have no memory at runtime. They are a compile-time only construct.

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.)

Check the source! expression.d has class SliceExp. Look down to where it handles tuples (AliasSeq is the user-visible name for what the compiler internally calls a tuple).

Slicing a tuple creates a new tuple that refers to the same objects as the previous one. So it doesn't deep copy... but remember this is irrelevant to any D program because an AliasSeq is just a compile-time list of constants anyway and thus cannot be modified and does not actually have a memory address in the generated program anyway.

Reply via email to