std.meta

Templates to manipulate template parameter sequences (also known as alias sequences).

Some operations on alias sequences are built into the language, such as S[i], which accesses the element at index i in the sequence. S[low .. high] returns a new alias sequence that is a slice of the old one.

For more information, see Compile-time Sequences.

Note: Several templates in this module use or operate on eponymous templates that take a single argument and evaluate to a boolean constant. Such templates are referred to as template predicates.

CategoryTemplates
Building blocksAlias AliasSeq aliasSeqOf
Alias sequence filteringErase EraseAll Filter NoDuplicates Stride
Alias sequence type hierarchyDerivedToFront MostDerived
Alias sequence transformationRepeat Replace ReplaceAll Reverse staticMap staticSort
Alias sequence searchingallSatisfy anySatisfy staticIndexOf
Template predicatestemplateAnd templateNot templateOr staticIsSorted
Template instantiationApplyLeft ApplyRight Instantiate

References: Based on ideas in Table 3.1 from Modern C++ Design, Andrei Alexandrescu (Addison-Wesley Professional, 2001)

Members

Aliases

Alias
alias Alias(alias a) = a
alias Alias(T) = T

Allows aliasing of any single symbol, type or compile-time expression.

AliasSeq
alias AliasSeq(TList...) = TList

Creates a sequence of zero or more aliases. This is most commonly used as template parameters or arguments.

Instantiate
alias Instantiate(alias Template, Params...) = Template!Params

Instantiates the given template with the given parameters.

Enums

staticIsSorted
eponymoustemplate staticIsSorted(alias cmp, items...)

Checks if an AliasSeq is sorted according to cmp.

Templates

ApplyLeft
template ApplyLeft(alias Template, args...)
ApplyRight
template ApplyRight(alias Template, args...)

Partially applies Template by binding its first (left) or last (right) arguments to args.

DerivedToFront
template DerivedToFront(TList...)

Returns an AliasSeq with the elements of TList sorted so that the most derived types come first.

Erase
template Erase(args...)

Returns an AliasSeq created from args[1 .. $] with the first occurrence, if any, of args[0] removed.

EraseAll
template EraseAll(args...)

Returns an AliasSeq created from args[1 .. $] with all occurrences, if any, of args[0] removed.

Filter
template Filter(alias pred, args...)

Filters an AliasSeq using a template predicate. Returns an AliasSeq of the elements which satisfy the predicate.

MostDerived
template MostDerived(T, TList...)

Returns the type from TList that is the most derived from type T. If no such type is found, T is returned.

NoDuplicates
template NoDuplicates(args...)

Returns an AliasSeq created from args with all duplicate types removed.

Repeat
template Repeat(size_t n, items...)

Creates an AliasSeq which repeats items exactly n times.

Replace
template Replace(T, U, TList...)
template Replace(alias T, U, TList...)
template Replace(T, alias U, TList...)
template Replace(alias T, alias U, TList...)

Returns an AliasSeq created from TList with the first occurrence of T, if found, replaced with U.

ReplaceAll
template ReplaceAll(args...)

Returns an AliasSeq created from args[2 .. $] with all occurrences of args[0], if any, replaced with args[1].

Reverse
template Reverse(args...)

Returns an AliasSeq created from args with the order reversed.

Stride
template Stride(int stepSize, Args...)

Selects a subset of Args by stepping with fixed stepSize over the sequence. A negative stepSize starts iteration with the last element.

aliasSeqOf
template aliasSeqOf(alias iter)

Converts any foreach-iterable entity (e.g. an input range) to an alias sequence.

allSatisfy
template allSatisfy(alias F, T...)

Tests whether all given items satisfy a template predicate, i.e. evaluates to F!(T[0]) && F!(T[1]) && ... && F!(T[$ - 1]).

anySatisfy
template anySatisfy(alias F, T...)

Tests whether any given items satisfy a template predicate, i.e. evaluates to F!(T[0]) || F!(T[1]) || ... || F!(T[$ - 1]).

staticIndexOf
template staticIndexOf(args...)

Returns the index of the first occurrence of args[0] in the sequence args[1 .. $]. args may be types or compile-time values. If not found, -1 is returned.

staticMap
template staticMap(alias F, Args...)

Evaluates to AliasSeq!(F!(T[0]), F!(T[1]), ..., F!(T[$ - 1])).

staticSort
template staticSort(alias cmp, items...)

Sorts an AliasSeq using cmp.

templateAnd
template templateAnd(Preds...)

Combines several template predicates using logical AND, i.e. constructs a new predicate which evaluates to true for a given input T if and only if all of the passed predicates are true for T.

templateNot
template templateNot(alias pred)

Negates the passed template predicate.

templateOr
template templateOr(Preds...)

Combines several template predicates using logical OR, i.e. constructs a new predicate which evaluates to true for a given input T if and only at least one of the passed predicates is true for T.

Meta