D Programming Language 2.0

- Comments
- D
- Search
- Home

Last update Thu Sep 16 11:26:02 2010

# std.typetuple

Templates with which to manipulate type tuples (also known as type lists).

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

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

License:
Boost License 1.0.

Authors:
Walter Bright

Copyright Digital Mars 2005 - 2009. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

http:
//www.boost.org/LICENSE_1_0.txt)

template TypeTuple(TList...)
  Creates a typetuple out of a sequence of zero or more types.

  Example:

       import std.typetuple;
       alias TypeTuple!(int, double) TL;

       int foo(TL td)  // same as int foo(int, double);
       {
          return td[0] + cast(int)td[1];
       }

  Example:

       TypeTuple!(TL, char)
       // is equivalent to:
       TypeTuple!(int, double, char)

template staticIndexOf(T,TList...)
template staticIndexOf(alias T,TList...)
  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.

  Example:

       import std.typetuple;
       import std.stdio;

       void foo()
       {
          writefln("The index of long is ",
                staticIndexOf!(long, TypeTuple!(int, long, double)));
          // prints: The index of long is 1
       }

alias IndexOf;
  Kept for backwards compatibility

template Erase(T,TList...)
template Erase(alias T,TList...)
  Returns a typetuple created from TList with the first occurrence, if any, of T removed.

  Example:

       Erase!(long, int, long, double, char)
       // is the same as:
       TypeTuple!(int, double, char)

template EraseAll(T,TList...)
template EraseAll(alias T,TList...)
  Returns a typetuple created from TList with the all occurrences, if any, of T removed.

  Example:

       alias TypeTuple!(int, long, long, int) TL;

       EraseAll!(long, TL)
       // is the same as:
       TypeTuple!(int, int)

template NoDuplicates(TList...)
  Returns a typetuple created from TList with the all duplicate types removed.

  Example:

       alias TypeTuple!(int, long, long, int, float) TL;

       NoDuplicates!(TL)
       // is the same as:
       TypeTuple!(int, long, float)

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 a typetuple created from TList with the first occurrence of type T, if found, replaced with type U.

  Example:

       alias TypeTuple!(int, long, long, int, float) TL;

       Replace!(long, char, TL)
       // is the same as:
       TypeTuple!(int, char, long, int, float)

template ReplaceAll(T,U,TList...)
template ReplaceAll(alias T,U,TList...)
template ReplaceAll(T,alias U,TList...)
template ReplaceAll(alias T,alias U,TList...)
  Returns a typetuple created from TList with all occurrences of type T, if found, replaced with type U.

  Example:

       alias TypeTuple!(int, long, long, int, float) TL;

       ReplaceAll!(long, char, TL)
       // is the same as:
       TypeTuple!(int, char, char, int, float)

template Reverse(TList...)
  Returns a typetuple created from TList with the order reversed.

  Example:

       alias TypeTuple!(int, long, long, int, float) TL;

       Reverse!(TL)
       // is the same as:
       TypeTuple!(float, int, long, long, int)

template MostDerived(T,TList...)
  Returns the type from TList that is the most derived from type T. If none are found, T is returned.

  Example:

       class A { }
       class B : A { }
       class C : B { }
       alias TypeTuple!(A, C, B) TL;

       MostDerived!(Object, TL) x;  // x is declared as type C

template DerivedToFront(TList...)
  Returns the typetuple TList with the types sorted so that the most derived types come first.

  Example:

       class A { }
       class B : A { }
       class C : B { }
       alias TypeTuple!(A, C, B) TL;

       DerivedToFront!(TL)
       // is the same as:
       TypeTuple!(C, B, A)

template staticMap(alias F,T...)
  Evaluates to TypeTuple!(F[T[0]], F[T[1]], ..., F[T[$ - 1]]).

  Example:

      alias staticMap!(Unqual, int, const int, immutable int) T;
      static assert(is(T == TypeTuple!(int, int, int)));

template allSatisfy(alias F,T...)
  Evaluates to F[T[0]] && F[T[1]] && ... && F[T[$ - 1]].

  Example:

      static assert(!allSatisfy!(isIntegral, int, double));
      static assert(allSatisfy!(isIntegral, int, long));

template anySatisfy(alias F,T...)
  Evaluates to F[T[0]] || F[T[1]] || ... || F[T[$ - 1]].

  Example:

      static assert(!anySatisfy!(isIntegral, string, double));
      static assert(anySatisfy!(isIntegral, int, double));

Copyright Digital Mars 2005 - 2009. | Page generated by Ddoc.