Slicing AliasSeq-s
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Mon Dec 21 07:16:37 PST 2015
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.
More information about the Digitalmars-d
mailing list