www.digitalmars.com

D Programming Language 1.0

Last update Mon Dec 31 10:53:29 2012

std.traits

Templates with which to extract information about types at compile time.

Source:
std/traits.d

template ReturnType(alias dg)
template ReturnType(dg)
Get the type of the return value from a function, a pointer to function, or a delegate.

Example:
 import std.traits;
 int foo();
 ReturnType!(foo) x;   // x is declared as int


template ParameterTypeTuple(alias dg)
template ParameterTypeTuple(dg)
Get the types of the paramters to a function, a pointer to function, or a delegate as a tuple.

Example:
 import std.traits;
 int foo(int, long);
 void bar(ParameterTypeTuple!(foo));      // declares void bar(int, long);
 void abc(ParameterTypeTuple!(foo)[1]);   // declares void abc(long);


template FieldTypeTuple(S)
Get the types of the fields of a struct or class. This consists of the fields that take up memory space, excluding the hidden fields like the virtual function table pointer.

template BaseTypeTuple(A)
Get a TypeTuple of the base class and base interfaces of this class or interface.

Example:
 import std.traits, std.typetuple, std.stdio;
 interface I { }
 class A { }
 class B : A, I { }

 void main()
 {
     alias BaseTypeTuple!(B) TL;
     writefln(typeid(TL));    // prints: (A,I)
 }


template isStaticArray(T)
Detect whether type T is a static array.

template isExpressionTuple(T...)
Tells whether the tuple T is an expression tuple.