D 1.0   D 2.0
About Japanese Translation

www.digitalmars.com
Last update Thu May 13 17:38:34 2010

std.traits

コンパイル時に 型の情報を取り出すためのテンプレートです。

License:
Boost License 1.0.

Authors:
Walter Bright, Tomasz Stachowiak (isExpressionTuple), Andrei Alexandrescu

template ReturnType(alias dg)
関数か、関数ポインタ、デリゲート、 opCallメソッドを持つ構造体、opCallメソッドを持つ構造体へのポインタ、 あるいはopCallメソッドを持つクラス から返値の型を取得します。

Example:
 import std.traits;
 int foo();
 ReturnType!(foo) x;   // x は int 型

template ParameterTypeTuple(alias dg)
template ParameterTypeTuple(dg,dummy = void)
関数か、関数ポインタ、デリゲート、 あるいは opCall メソッドを持つ構造体、構造体へのポインタ、クラスから 引数の型をタプルとして取得します。

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

template FieldTypeTuple(S)
構造体かクラスをフィールドのタプルに変換したときの型を取得します。 これは、仮想関数テーブルへのポインタのような隠しフィールドを除いた、 メモリ空間を消費するフィールドのみで構成される タプルとなります。

template RepresentationTypeTuple(T...)
構造体やクラスのフィールドのプリミティブな型のタプルを topological order で返します。

Example:
struct S1 { int a; float b; }
struct S2 { char[] a; union { S1 b; S1 * c; } }
alias RepresentationTypeTuple!(S2) R;
assert(R.length == 4
    && is(R[0] == char[]) && is(R[1] == int)
    && is(R[2] == float) && is(R[3] == S1*));

template hasAliasing(T...)
T の表現に以下のいずれかが含まれているときに、true を返します:
  1. 生のポインタ U*U がimmutableでないもの
  2. 配列 U[]U が immutable でないもの
  3. クラス参照 CC が immutable でないもの

template BaseTypeTuple(A)
指定したクラスやインターフェイスの基底型と基底インターフェイスからなる 型タプルを返します。BaseTypeTuple!(Object) は空の型タプルを返します。

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

 void main()
 {
     alias BaseTypeTuple!(B) TL;
     writeln(typeid(TL));	// (A,I) を表示
 }

template BaseClassesTuple(T)
このクラスの全ての基底クラスを、降順の型タプルとして返します。 インターフェイスは含まれません。BaseClassesTuple!(Object) は空の型タプルになります。

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

 void main()
 {
     alias BaseClassesTuple!(C) TL;
     writeln(typeid(TL));	// (B,A,Object) を表示
 }

template InterfacesTuple(T)
このクラスや基底クラスの実装する全てのインターフェイスを並べた 型タプルを返します。複数回implementsされたインターフェイスでも 重複列挙されることはありません。InterfacesTuple!(Object) は空の型タプルを返します。

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

 void main()
 {
     alias InterfacesTuple!(C) TL;
     writeln(typeid(TL));	// (I1, I2) を表示
 }

template TransitiveBaseTypeTuple(T)
クラス T の全ての基底クラスを降順に並べ、 その後ろにインターフェイスを並べた型タプルを返します。 TransitiveBaseTypeTuple!(Object) は空の型タプルになります。

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

 void main()
 {
     alias TransitiveBaseTypeTuple!(C) TL;
     writeln(typeid(TL));	// (B,A,Object,I) を表示
 }

template CommonType(T...)
指定した型全ての暗黙変換先となれる型を返します。 例えば、さまざまな初期化値から配列を生成する場合などに役に立ちます。 空リストを渡したときや、共通の型が存在しない場合は void を返します。

Example:
alias CommonType!(int, long, short) X;
assert(is(X == long));
alias CommonType!(int, char[], short) Y;
assert(is(Y == void));

template ImplicitConversionTargets(T)
T. からの暗黙変換先となりうる型全てのタプルを返します。

Important note:

このテンプレートが返す型のリストは、危険な変換を除いているため D 2.005 コンパイラが認めるものより保守的になっています。 例えば ImplicitConversionTargets!(double) には float は含まれません。

template isImplicitlyConvertible(From,To)
FromTo に暗黙変換可能か?

template isIntegral(T)
T が組み込みの整数型かどうかを判定します。bool, char, wchar, dchar は整数型とは見なされません。

template isFloatingPoint(T)
T が組み込みの浮動小数点数型かどうかを判定します。

template isNumeric(T)
T が組み込みの数値型(整数あるいは 浮動小数点数)かどうかを判定します。

template isSomeString(T)
T が組み込みの文字列型かどうかを判定します。

template isSomeChar(T)
T が組み込みの文字型かどうかを判定します。

template isAssociativeArray(T)
T が組み込みの連想配列型かどうかを判定します。

template isStaticArray(T : U[N],U,size_t N)
Tが静的配列かどうかを判定します。

template isDynamicArray(T,U = void)
型 T が動的配列型かどうかを判定します。

template isArray(T)
型 T が配列型かどうかを判定します。

template isPointer(T)
T がポインタ型かどうかを判定します。

template isExpressionTuple(T...)
タプル T が式タプルかどうか判定します。

template Unsigned(T)
T に対する unsigned 型を返します。 Tが整数型ではないばあい、コンパイルエラーになります。

template mostNegative(T)
数値型Tの負の最小値を返します。

template Unqual(T)
template Unqual(T : const(U),U)
template Unqual(T : immutable(U),U)
T についている修飾子があればすべて取り除きます。

Example:
static assert(is(Unqual!(int) == int));
static assert(is(Unqual!(const int) == int));
static assert(is(Unqual!(immutable int) == int));

template staticMap(alias F,T...)
型タプル 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...)
F[T[0]] && F[T[1]] && ... && F[T[$ - 1]] を返します。

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

template Select(bool condition,T,F)
真偽値 conditiontrue なら T への alias、そうでなければ F への alias となります。

Example:
alias Select!(size_t.sizeof == 4, int, long) Int;

A select(bool cond : true, A, B)(A a, lazy B b);
B select(bool cond : false, A, B)(lazy A a, B b);
condtrue ならば b を評価せずに a を返します。逆に false ならば a を評価せずに b を返します。