Templated Lists

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 16 12:22:53 PDT 2017


On Friday, June 16, 2017 19:07:49 Jolly James via Digitalmars-d wrote:
> I know that there are arrays, some strange container classes and
> so on.
>
> But how does one create and use a templated list in D that
> supports adding, removing and sorting items? One that can be used
> for structs and for classes?

AliasSeq is used to create a list of items - e.g. AliasSeq!(int, float). It
can hold types, expressions, or both. It's basically what you get when you
have a template argument list or parameter list or a function argument list
or parameter list - hence why it can hold a bit of a hodepodge of things and
why giving it a good name is rather difficult (its current name being short
for alias sequence). It used to be called TypeTuple but was renamed because
it doesn't only hold types, and it isn't really a tuple (it auto expands, so
you can't really nest them - e.g. AliasSeq!(int, float) and AliasSeq!(int,
AliasSeq!float) are going to end up being the same thing). Confusingly, the
language documentation tends to call it Tuple (not to be confused with
std.typecons.Tuple), even though it isn't really a tuple. But that largely
comes down to the fact that no one has a good name for the thing.

std.meta provides a variety of templates for operating on AliasSeqs with
predicates and whatnot, so it would be the main place to look if you want to
operate on an AliasSeq:

http://dlang.org/phobos/std_meta.html

And of course, std.traits helps with some of the building blocks -
particularly for creating compile-time predicates:

http://dlang.org/phobos/std_traits.html

- Jonathan M Davis



More information about the Digitalmars-d mailing list