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.
std.typelist
This module contains the TypeList type and related metafunctions. Authors:Arlen Avakian License:
Boost License 1.0 Source:
std/typelist2.d
- template _and(bool A,bool B)
- Boolean and.
Examples:
static assert(_and!(true, false) == false);
- template _or(bool A,bool B)
- Boolean or.
Examples:
static assert(_or!(true, false) == true);
- template _not(bool A)
- Boolean not.
Examples:
static assert(_not!(false));
- template _all(alias Pred,T...)
- Determines if all elements of the typetuple satisfy the predicate.
Examples:
static assert(_all!(isFloatingPoint, int, float, char) == false);
- template _any(alias Pred,T...)
- Determine if any element of the typetuple satisfies the predicate.
Examples:
static assert(_any!(isFloatingPoint, int, float, char) == true);
- template Id(T)
- Identity metafunction.
Examples:
static assert(Id!int == int);
- template Curry(alias Fun,Args...)
- Curries Fun by tying its first Args.length arguments to Args.
Examples:
alias Curry!(_and, true) true_and; static assert(true_and!true == true); static assert(true_and!false == false);
- struct TypeList(T...);
- Creates a typelist out of a sequence of zero or more types.
Examples:
alias TypeList!(int, float, long*) TL1; static assert(is(TL1.items == TypeTuple!(int, float, long*))); static assert(TL1.dim == 1); static assert(is(TL1.head == int)); static assert(is(TL1.tail == TypeList!(float, long*))); static assert(toString!TL1 == "[int,float,long*]");
- alias items;
- A typetuple of all the elements of the typelist.
- alias head;
- The first element of the typelist.
- alias last;
- The last element of the typelist.
- alias tail;
- The elements after the head of the typelist.
- alias init;
- All the elements of the typelist except the last one.
- string toString();
- Converts the typelist to a string representation.
- template isTypeList(T)
- Check to see if T is a TypeList.
- template _(string TL)
- Constructs a typelist. EXPERIMENTAL.
Examples:
alias _!"[int, double, uint]" TL1; static assert(is(TL1 == TypeList!(int, double, uint))); alias _!"[[char],[float,double]]" TL2; static assert(is(TL2 == TypeList!(TypeList!(char), TypeList!(float, double))));
- template Head(TL) if (isTypeList!(TL))
- Extract the first element of a typelist.
- template Last(TL) if (isTypeList!(TL))
- Extract the last element of a typelist.
- template Tail(TL) if (isTypeList!(TL))
- Extract the elements after the head of a typelist.
- template Init(TL) if (isTypeList!(TL))
- Return all the elements of a typelist except the last one.
- template Empty(TL) if (isTypeList!(TL))
- Test whether a typelist is empty.
- template Length(TL) if (isTypeList!(TL))
- Returns the length of a typelist.
- template Append(TL1,TL2) if (isTypeList!(TL1) && isTypeList!(TL2))
- Append two typelists.
Examples:
alias TypeList!(int) TL1; alias TypeList!(char) TL2; alias Append!(TL1, TL2) R1; static assert(is(R1 == TypeList!(int, char)));
- template Append(TL,T) if (isTypeList!(TL) && !isTypeList!(T))
- Append a type to a typelist.
Examples:
alias TypeList!(float, double) TL1; alias Append!(TL1, real) R1; static assert(is(R1 == TypeList!(float, double, real)));
- template Cons(A,B) if (isTypeList!(B))
- Prepend a type to a typelist.
Examples:
alias TypeList!(float) TL1; alias Cons!(char, TL1) R1; static assert(is(R1 == TypeList!(char, float)));
- template toString(TL) if (isTypeList!(TL))
- Converts a TypeList to string.
Examples:
static assert(toString!(TypeList!(float, real)) == "[float,real]");
- template sameTypes(T1,T2)
- Returns true if T1 and T2 are of the same type.
- template equal(alias Pred,TL1,TL2) if (isTypeList!(TL1) && isTypeList!(TL2))
- Returns true if and only if the two typelists compare equal element for element, according to binary predicate Pred.
- template Map(alias Fun,TL) if (isTypeList!(TL))
- A new typelist is obtained by applying Fun to each item of TL.
Examples:
alias TypeList!(immutable double, int, const char) TL1; alias Map!(Unqual, TL1) R1; static assert(is(R1 == TypeList!(double, int, char)));
- template Reverse(TL) if (isTypeList!(TL))
- Returns the elements of a typelist in reverse order.
Examples:
alias TypeList!(int, double, char) TL1; alias Reverse!TL1 R1; static assert(is(R1 == TypeList!(char, double, int)));
- template Intersperse(T,TL) if (isTypeList!(TL))
- Intersperses T between the elements of the typelist.
Examples:
alias TypeList!(float, double, real) TL1; alias Intersperse!(string, TL1) R1; static assert(is(R1 == TypeList!(float, string, double, string, real)));
- template Transpose(TL) if (isTypeList!(TL))
- Transposes the rows and columns of its argument.
Examples:
alias TypeList!(TypeList!(float, double), TypeList!(int, long)) TL1; alias Transpose!(TL1) R1; static assert(is(R1 == TypeList!(TypeList!(float, int), TypeList!(double, long))));
- template Subsequences(TL) if (isTypeList!(TL))
- Returns the typelist of all subsequences of the types.
Examples:
alias TypeList!(char, int) TL1; alias Subsequences!TL1 R1; static assert(is(R1 == TypeList!(TypeList!(), TypeList!char, TypeList!int, TypeList!(char, int))));
- template Permutations(xs0) if (isTypeList!(xs0))
- Returns the typelist of all permutations of the argument.
Examples:
alias Permutations!(TypeList!(int, uint, char)) R1; static assert(toString!R1 == "[[int,uint,char],[uint,int,char],[char,uint,int],[uint,char,int],[char,int,uint],[int,char,uint]]");
- template Foldl(alias Fun,Z,TL) if (isTypeList!(TL))
- Reduces a n-dimensional typelist from left to right.
Fun is the binary operator, and Z is the starting type.
Examples:
struct C(int n) { enum cardinal = n; } template Minus(A, B) { alias C!(A.cardinal - B.cardinal) Minus; } alias TypeList!(C!2, C!3, C!7, C!4) TL1; alias Foldl!(Minus, C!0, TL1) R1; static assert(is(R1 == C!(-16)));
- template Foldl1(alias Fun,TL) if (isTypeList!(TL))
- Foldl1 is a variant of Foldl that has no starting type argument.
- template Foldr(alias Fun,Z,TL) if (isTypeList!(TL))
- Reduces a n-dimensional typelist from right to left.
Fun is the binary operator, and Z is the starting type.
Examples:
alias TypeList!(C!2, C!3, C!7, C!4) TL1; alias Foldr!(Minus, C!0, TL1) R1; static assert(is(R1 == C!(2)));
- template Foldr1(alias Fun,TL) if (isTypeList!(TL))
- Foldr1 is a variant of Foldr that has no starting type argument.
- template Concat(TL) if (isTypeList!(TL))
- Concatenate a typelist of typelists.
Examples:
alias Concat!(TypeList!(TypeList!(int, uint), TypeList!char, TypeList!(long,ulong))) R1; static assert(is(R1 == TypeList!(int, uint, char, long, ulong)));
- template ConcatMap(alias Fun,TL) if (isTypeList!(TL))
- Map a metafunction over a typelist and concatenate the results.
Examples:
template Twice(T) { alias TypeList!(T, T) Twice; } alias TypeList!(char, int, long) TL1; alias ConcatMap!(Twice, TL1) R1; static assert(is(R1 == TypeList!(char, char, int, int, long, long)));
- template all(alias Pred,TL) if (isTypeList!(TL))
- Determines if all elements of the typelist satisfy the predicate.
Examples:
static assert(all!(isFloatingPoint, TypeList!(int, float, char)) == false);
- template any(alias Pred,TL) if (isTypeList!(TL))
- Determines if any element of the typelist satisfies the predicate.
Examples:
static assert(any!(isFloatingPoint, TypeList!(int, float, char)) == true);
- template Scanl(alias Fun,Q,TL) if (isTypeList!(TL))
- Returns a n-dimensional typelist of successive reduced types from the left.
Examples:
alias TypeList!(C!1, C!2, C!3) TL1; alias Scanl!(Minus, C!4, TL1) R1; static assert(is(R1 == TypeList!(C!4, C!3, C!1, C!(-2))));
- template Scanl1(alias Fun,TL) if (isTypeList!(TL))
- Scanl1 is a variant of Scanl that has no starting type argument.
- template Scanr(alias Fun,Q0,TL) if (isTypeList!(TL))
- Returns a n-dimensional typelist of successive reduced typess from the right.
Examples:
alias TypeList!(C!1, C!2, C!3) TL1; alias Scanl!(Minus, C!4, TL1) R1; static assert(is(R1 == TypeList!(C!(-2), C!3, C!(-1), C!4)));
- template Scanr1(alias Fun,TL) if (isTypeList!(TL))
- Scanr1 is a variant of Scanr that has no starting type argument.
- template IterateN(int N,alias Fun,T)
- Returns a typelist of length N of repeated applications of Fun to T.
Examples:
struct _1 { enum value = 1; } template TimesTwo(T) { enum string result = to!string(T.value * 2); mixin(xformat("struct _%1$s { enum value = %1$s; } alias _%1$s TimesTwo;", result)); } alias IterateN!(6, TimesTwo, _1) R1; static assert(toString!R1 == "[_1,_2,_4,_8,_16,_32]");
- template Replicate(int N,T)
- Returns a typelist of length N with T the type of every element.
Examples:
alias Replicate!(3, char) R1; static assert(is(R1 == TypeList!(char, char, char)));
- template TakeN(int N,TL) if (isTypeList!(TL))
- Returns the prefix of TL of length N, or TL itself if N > TL.length.
Examples:
alias TakeN!(3, TypeList!(C!1, C!2, C!3, C!4, C!5)) R1; static assert(is(R1 == TypeList!(C!1, C!2, C!3)));
- template TakeWhile(alias Pred,TL) if (isTypeList!(TL))
- Returns the longest prefix of TL of elements that satisfy Pred.
Examples:
alias TypeList!(int, long, char, uint, float) TL1; alias TakeWhile!(isIntegral, TL1) R1; static assert(is(R1 == TypeList!(int, long)));
- template DropWhile(alias Pred,TL) if (isTypeList!(TL))
- Returns the suffix remaining after TakeWhile!(Pred, TL).
Examples:
alias TypeList!(int, uint, long, float, double, int) TL1; alias DropWhile!(isIntegral, TL1) R1; static assert(is(R1 == TypeList!(float, double, int)));
- template Filter(alias Pred,TL) if (isTypeList!(TL))
- Returns the typelist of those elements that satisfy the predicate.
Examples:
alias TypeList!(int, double, uint, float, long, ulong) TL1; alias Filter!(isIntegral, TL1) R1; static assert(is(R1 == TypeList!(int, uint, long, ulong)));
- template ZipWith(alias Fun,TL1,TL2) if (isTypeList!(TL1) && isTypeList!(TL2))
- Takes two typelists and zips with the metafunction Fun.
Examples:
alias TypeList!(int, char, double) TL1; alias TypeList!(float, long) TL2; alias ZipWith!(CommonType, TL1, TL2) R1; static assert(is(R1 == TypeList!(float, long)));
- template NubBy(alias Pred,TL) if (isTypeList!(TL))
- Removes duplicate elements from a typelist.
Examples:
alias TypeList!(int, double, float, int, double, double, char) TL1; alias NubBy!(sameTypes, TL1) R1; static assert(is(R1 == TypeList!(int, double, float, char)));
- template DeleteBy(alias Pred,X,TL) if (isTypeList!(TL))
- Removes the first occurrence of X from its typelist argument using Pred.
Examples:
alias TypeList!(int, float, char, double) TL1; alias DeleteBy!(sameTypes, float, TL1) R1; static assert(is(R1 == TypeList!(int, char, double)));
- template UnionBy(alias Pred,TL1,TL2) if (isTypeList!(TL1) && isTypeList!(TL2))
- Returns the typelist union of the two typelists.
Examples:
alias TypeList!(int, double, float) TL1; alias TypeList!(char, double, int) TL2; alias UnionBy!(sameTypes, TL1, TL2) R1; static assert(is(R1 == TypeList!(int, double, float, char)));
- template IntersectBy(alias Pred,TL1,TL2) if (isTypeList!(TL1) && isTypeList!(TL2))
- Returns the typelist intersection of two typelists.
Examples:
alias TypeList!(int, char, float, double) TL1; alias TypeList!(double, double, uint) TL2; alias IntersectBy!(sameTypes, TL1, TL2) R1; static assert(is(R1 == TypeList!(double)));
- template GroupBy(alias Pred,TL) if (isTypeList!(TL))
- Splits TL into a typelist of typelists. Pred provides the equality test.
Examples:
alias TypeList!(int, int, char, float, float) TL1; alias GroupBy!(sameTypes, TL1) R1; static assert(is(R1 == TypeList!(TypeList!(int, int), TypeList!(char), TypeList!(float, float))));
- template SortBy(alias Less,TL) if (isTypeList!(TL))
- Returns a sorted typelist.
Examples:
struct S1 { enum ordinal = 1; } struct S2 { enum ordinal = 2; } struct S3 { enum ordinal = 3; } struct S4 { enum ordinal = 4; } template Less(T1, T2) { static if(T1.ordinal < T2.ordinal) enum Less = true; else enum Less = false; } alias TypeList!(S1, S3, S2, S4, S1, S2, S4) TL1; alias SortBy!(Less, TL1) R1; static assert(is(R1 == TypeList!(S1, S1, S2, S2, S3, S4, S4)));