View source code Display the source code in std/meta.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Module std.meta

Templates to manipulate template argument lists (also known as type lists).

Some operations on alias sequences are built in to the language, such as TL[n] which gets the nth type from the alias sequence. TL[lwr .. upr] returns a new type list that is a slice of the old one.

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.

References

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

Templates

Name Description
allSatisfy Tests whether all given items satisfy a template predicate, i.e. evaluates to F!(T[0]) && F!(T[1]) && ... && F!(T[$ - 1]).
anySatisfy Tests whether any given items satisfy a template predicate, i.e. evaluates to F!(T[0]) || F!(T[1]) || ... || F!(T[$ - 1]).
DerivedToFront Returns the typetuple TList with the types sorted so that the most derived types come first.
Filter Filters an AliasSeq using a template predicate. Returns a AliasSeq of the elements which satisfy the predicate.
MostDerived Returns the type from TList that is the most derived from type T. If none are found, T is returned.
NoDuplicates Returns a typetuple created from TList with the all duplicate types removed.
Reverse Returns a typetuple created from TList with the order reversed.
staticMap Evaluates to AliasSeq!(F!(T[0]), F!(T[1]), ..., F!(T[$ - 1])).
templateAnd 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 Negates the passed template predicate.
templateOr 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.

Enum values

Name Type Description
staticIndexOf Returns the index of the first occurrence of type T in the sequence of zero or more types TList. If not found, -1 is returned.

Aliases

Name Type Description
AliasSeq TList Creates a sequence of zero or more aliases. This is most commonly used as template parameters or arguments.
Erase GenericErase!(T,TList) Returns a typetuple created from TList with the first occurrence, if any, of T removed.
EraseAll GenericEraseAll!(T,TList) Returns a typetuple created from TList with the all occurrences, if any, of T removed.
IndexOf Kept for backwards compatibility
Replace GenericReplace!(T,U,TList) Returns a typetuple created from TList with the first occurrence of type T, if found, replaced with type U.
ReplaceAll GenericReplaceAll!(T,U,TList) Returns a typetuple created from TList with all occurrences of type T, if found, replaced with type U.

Authors

Walter Bright, David Nadlinger

License

Boost License 1.0.

Comments