std.traits
ソースstd/traits.d
- template
InoutOf
(T) - Parameters:
T 修飾する型 Returns: xml-ph-0000@deepl.internal修飾子を追加する。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalT inout 修飾語句が追加された。Examples:static assert(is(InoutOf!(int) == inout int)); static assert(is(InoutOf!(inout int) == inout int)); static assert(is(InoutOf!(const int) == inout const int)); static assert(is(InoutOf!(shared int) == inout shared int));
- template
ConstOf
(T) - Parameters:
T 修飾する型は Returns: xml-ph-0000@deepl.internal修飾語句を追加した。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalT const 修飾語句が追加された。Examples:static assert(is(ConstOf!(int) == const int)); static assert(is(ConstOf!(const int) == const int)); static assert(is(ConstOf!(inout int) == const inout int)); static assert(is(ConstOf!(shared int) == const shared int));
- template
SharedOf
(T) - Parameters:
T 修飾する型は Returns: xml-ph-0000@deepl.internal修飾語句を追加した。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalT shared 修飾語句が追加された。Examples:static assert(is(SharedOf!(int) == shared int)); static assert(is(SharedOf!(shared int) == shared int)); static assert(is(SharedOf!(inout int) == shared inout int)); static assert(is(SharedOf!(immutable int) == shared immutable int));
- template
SharedInoutOf
(T) - Parameters:
T 修飾する型は Returns: xml-ph-0000@deepl.internalとxml-ph-0001@deepl.internalの修飾語句が追加される。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalT inout と の修飾語句が追加される。sharedExamples:static assert(is(SharedInoutOf!(int) == shared inout int)); static assert(is(SharedInoutOf!(int) == inout shared int)); static assert(is(SharedInoutOf!(const int) == shared inout const int)); static assert(is(SharedInoutOf!(immutable int) == shared inout immutable int));
- template
SharedConstOf
(T) - Parameters:
T 修飾する型は Returns: xml-ph-0000@deepl.internalとxml-ph-0001@deepl.internalの修飾語句が追加される。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalT const と の修飾語句が追加される。sharedExamples:static assert(is(SharedConstOf!(int) == shared const int)); static assert(is(SharedConstOf!(int) == const shared int)); static assert(is(SharedConstOf!(inout int) == shared inout const int)); // 不変の変数は暗黙的に共有され、constとなる static assert(is(SharedConstOf!(immutable int) == immutable int));
- template
SharedConstInoutOf
(T) - Parameters:
T 修飾する型は Returns: xml-ph-0000@deepl.internal、xml-ph-0001@deepl.internal、xml-ph-0002@deepl.internalの修飾語句が追加された。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalT const 、 、 の修飾語句が追加された。shared inoutExamples:static assert(is(SharedConstInoutOf!(int) == shared const inout int)); static assert(is(SharedConstInoutOf!(int) == const shared inout int)); static assert(is(SharedConstInoutOf!(inout int) == shared inout const int)); // 不変の変数は暗黙的に共有され、constとなる static assert(is(SharedConstInoutOf!(immutable int) == immutable int));
- template
ImmutableOf
(T) - Parameters:
T 修飾する型 Returns: xml-ph-0000@deepl.internal修飾語句を追加した。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalT immutable 修飾語句が追加された。Examples:static assert(is(ImmutableOf!(int) == immutable int)); static assert(is(ImmutableOf!(const int) == immutable int)); static assert(is(ImmutableOf!(inout int) == immutable int)); static assert(is(ImmutableOf!(shared int) == immutable int));
- template
QualifierOf
(T) - 指定された型T と同じ属性を適用できるテンプレートを生成する。 例えば、inout shared int を渡すと、SharedInoutOf が返される。Parameters:
T 修飾子をチェックする型 Returns:typetype指定された型からの修飾子テンプレートTExamples:static assert(__traits(isSame, QualifierOf!(shared const inout int), SharedConstInoutOf)); static assert(__traits(isSame, QualifierOf!(immutable int), ImmutableOf)); static assert(__traits(isSame, QualifierOf!(shared int), SharedOf)); static assert(__traits(isSame, QualifierOf!(shared inout int), SharedInoutOf)); import std.meta : Alias; static assert(__traits(isSame, QualifierOf!(int), Alias));
- template
packageName
(alias T) - 指定されたシンボルの完全なパッケージ名を取得する。package nameパッケージ名Examples:packageパッケージ
static assert(packageName!packageName == "std");
Examples:static assert(packageName!moduleName == "std");
- template
moduleName
(alias T) - 指定されたシンボルのモジュール名(パッケージを含む)を取得する。to get得るExamples:
static assert(moduleName!moduleName == "std.traits");
- enum auto
fullyQualifiedName
(T);
enum autofullyQualifiedName
(alias T); - 型またはシンボルの完全修飾名を取得する。 インテリジェントな型/シンボルから文字列への変換器として機能する。example例
例
module myModule; struct MyStruct {} static assert(fullyQualifiedName!(const MyStruct[]) == "const(myModule.MyStruct[])");
example例Examples:関数の戻り値の型、 関数へのポインタ、デリゲート、opCall を持つ構造体、 opCall を持つ構造体へのポインタ、 または xml-ph-00 を持つクラスを取得する。static assert(fullyQualifiedName!fullyQualifiedName == "std.traits.fullyQualifiedName");
- template
ReturnType
(alias func) if (isCallable!func) - 関数の戻り値の型、 関数へのポインタ、opCall を持つデリゲート、opCall を持つ構造体、 opCall を持つ構造体へのポインタ、 またはopCall を持つクラスを取得する。refは 型の一部ではなく、関数の属性であることに注意して ほしい(テンプレートを参照 functionAttributes。xml-ph-0000@deepl.internalxml-ph-0001@deepl.internal注釈: テンプレートのインスタンス化を減らすために、 引数の型が既知の場合はtypeof(() { return func(args); } ()) を、 基本的なテストのみが必要な場合はstatic if (is(typeof(func) Ret == return)) を使用することを検討する。Examples:
int foo(); ReturnType!foo x; // xはintと宣言される
- template
Parameters
(alias func) if (isCallable!func) - タプルとして、関数のパラメータの型、関数へのポインタ、 デリゲート、opCall を持つ構造体、opCall を持つ構造体へのポインタ、またはopCall を持つクラスを取得する。emailemailExamples:
int foo(int, long); void bar(Parameters!foo); // void bar(int, long)と宣言する; void abc(Parameters!foo[1]); // void abc(long)と宣言する;
- alias
ParameterTypeTuple
= Parameters(alias func) if (isCallable!func); - 代替名で、 Parameters、レガシー互換性を保つために保持されている。
- template
arity
(alias func) if (isCallable!func && (variadicFunctionStyle!func == Variadic.no)) - func 関数の引数の数を返す。 可変長引数関数ではarityは未定義である。arityarityExamples:
void foo(){} static assert(arity!foo == 0); void bar(uint){} static assert(arity!bar == 1); void variadicFoo(uint...){} static assert(!__traits(compiles, arity!variadicFoo));
- enum
ParameterStorageClass
: uint;
templateParameterStorageClassTuple
(alias func) if (isCallable!func) - 関数のパラメータのストレージクラスのタプルを取得する。Parameters:
func 関数シンボルまたは関数、デリゲート、関数へのポインタの型 Returns:function symbol機能シンボルParameterStorageClassビットのタプルExamples:alias STC = ParameterStorageClass; // 列挙型名を短くする void func(ref int ctx, out real result, in real param, void* ptr) { } alias pstc = ParameterStorageClassTuple!func; static assert(pstc.length == 4); // パラメータ数 static assert(pstc[0] == STC.ref_); static assert(pstc[1] == STC.out_); version (none) { // TODO: DMD PR (dlang/dmd#11474)がマージされたら、 // バージョニングと2番目のテストを削除する static assert(pstc[2] == STC.in_); // これは現在の挙動であり、`in`がエイリアスではないことが修正される前のものだ static assert(pstc[2] == STC.scope_); } static assert(pstc[3] == STC.none);
none
in_
ref_
out_
lazy_
scope_
return_
- これらのフラグは、複雑なストレージクラスを表すために、ビット単位でOR演算を実行することができる。
- enum ParameterStorageClass
extractParameterStorageClassFlags
(Attribs...); - Parameters:
Attribs 戻り値は__traits(getParameterStorageClasses) Returns: 等価なもののビット単位の論理和OROR等価なsのビット単位のOR演算結果 ParameterStorageClassenum。Examples:get取得static void func(ref int ctx, out real result); enum param1 = extractParameterStorageClassFlags!( __traits(getParameterStorageClasses, func, 0) ); static assert(param1 == ParameterStorageClass.ref_); enum param2 = extractParameterStorageClassFlags!( __traits(getParameterStorageClasses, func, 1) ); static assert(param2 == ParameterStorageClass.out_); enum param3 = extractParameterStorageClassFlags!( __traits(getParameterStorageClasses, func, 0), __traits(getParameterStorageClasses, func, 1) ); static assert(param3 == (ParameterStorageClass.ref_ | ParameterStorageClass.out_));
- template
ParameterIdentifierTuple
(alias func) if (isCallable!func) - 関数シンボルへのパラメータの識別子をタプルとして取得する。to get得るExamples:
int foo(int num, string name, int); static assert([ParameterIdentifierTuple!foo] == ["num", "name", ""]);
- template
ParameterDefaults
(alias func) if (isCallable!func) - 関数シンボルのパラメータのデフォルト値をタプルとして取得する。 パラメータにデフォルト値がない場合は、代わりにvoid が返される。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:
int foo(int num, string name = "hello", int[] = [1,2,3], lazy int x = 0); static assert(is(ParameterDefaults!foo[0] == void)); static assert( ParameterDefaults!foo[1] == "hello"); static assert( ParameterDefaults!foo[2] == [1,2,3]); static assert( ParameterDefaults!foo[3] == 0);
- alias
ParameterDefaultValueTuple
= ParameterDefaults(alias func) if (isCallable!func); - 代替名は、 ParameterDefaults、レガシーとの互換性を保つために残されている。
- enum
FunctionAttribute
: uint;
templatefunctionAttributes
(alias func) if (isCallable!func) - 関数func のFunctionAttributeマスクを返す。See Also:xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:
alias FA = FunctionAttribute; // 列挙型名を短縮する real func(real x) pure nothrow @safe { return x; } static assert(functionAttributes!func & FA.pure_); static assert(functionAttributes!func & FA.safe); static assert(!(functionAttributes!func & FA.trusted)); // @trustedではない
none
pure_
nothrow_
ref_
property
trusted
safe
nogc
system
const_
immutable_
inout_
shared_
return_
scope_
live
- これらのフラグは、複雑な属性を表すためにビット単位でOR結合することができる。
- template
hasFunctionAttributes
(args...) if (args.length > 0 && isCallable!(args[0]) && allSatisfy!(isSomeString, typeof(args[1..$]))) - 関数に指定された属性がアタッチされているかどうかを確認する。Parameters:
args チェックする関数、それに続く 可変長引数関数属性(文字列) Returns: 、関数に属性のリストが添付されている場合はxml-ph-0000@deepl.internal、そうでない場合はxml-ph-0000@deepl.internalxml-ph-0000@deepl.internaltrue、関数に属性のリストが添付されている場合はfalse 、そうでない場合はSee Also:functionfunctionExamples:xml-ph-0000@deepl.internal が xml-ph-0001@deepl.internal または xml-ph-0002@deepl.internal の場合。real func(real x) pure nothrow @safe; static assert(hasFunctionAttributes!(func, "@safe", "pure")); static assert(!hasFunctionAttributes!(func, "@trusted")); // テンプレートでは属性は自動的に推論される bool myFunc(T)(T b) { return !b; } static assert(hasFunctionAttributes!(myFunc!bool, "@safe", "pure", "@nogc", "nothrow")); static assert(!hasFunctionAttributes!(myFunc!bool, "shared"));
- template
isSafe
(alias func) if (isCallable!func) - true func が または の場合。@safe @trustedxml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:
@safe int add(int a, int b) {return a+b;} @trusted int sub(int a, int b) {return a-b;} @system int mul(int a, int b) {return a*b;} static assert( isSafe!add); static assert( isSafe!sub); static assert(!isSafe!mul);
- enum auto
isUnsafe
(alias func); - true func が の場合。@systemxml-ph-0001@deepl.internalxml-ph-0001@deepl.internalExamples:
@safe int add(int a, int b) {return a+b;} @trusted int sub(int a, int b) {return a-b;} @system int mul(int a, int b) {return a*b;} static assert(!isUnsafe!add); static assert(!isUnsafe!sub); static assert( isUnsafe!mul);
- template
functionLinkage
(alias func) if (isCallable!func) - 関数のリンク属性を決定する。Parameters: 関数シンボル、または関数、デリゲート、関数へのポインタの型
func 関数シンボル、または関数、デリゲート、関数へのポインタの型を決定する。 Returns: 「D」、「C」、「C++」、「Windows」、「Objective-C」、または「System」の文字列のいずれか。systemSystem"D"、"C"、"C++"、"Windows"、"Objective-C"、または"System"の文字列のいずれか。Examples:extern(D) void Dfunc() {} extern(C) void Cfunc() {} static assert(functionLinkage!Dfunc == "D"); static assert(functionLinkage!Cfunc == "C"); string a = functionLinkage!Dfunc; writeln(a); // "D" auto fp = &Cfunc; string b = functionLinkage!fp; writeln(b); // "C"
- enum
Variadic
: int;
templatevariadicFunctionStyle
(alias func) if (isCallable!func) - 可変長引数関数の種類を決定する。Parameters:
func 関数シンボルまたは関数、デリゲート、関数へのポインタの型 Returns:enumVariadic列挙型 可変長Examples:void func() {} static assert(variadicFunctionStyle!func == Variadic.no); extern(C) int printf(const char*, ...); static assert(variadicFunctionStyle!printf == Variadic.c);
no
- 関数は可変長引数ではない。
c
- 関数は、"C言語のスタイル"の可変長引数関数であり、core.stdc.stdarg
d
- "関数"は"D言語のスタイル"の可変長引数関数であり、__argptr と__arguments を使用する。
typesafe
- 関数は型安全な可変長引数関数である。
- template
FunctionTypeOf
(alias func) if (isCallable!func) - 関数型は、呼び出し可能なオブジェクトfunc 、または関数ポインタ/デリゲート型から取得する。プロパティ関数で組み込みのtypeof を使用すると、プロパティ関数自体ではなく、プロパティ値の型が返される。 それでも、
FunctionTypeOf
プロパティの関数型を取得することはできる。value通常注釈: 関数型と関数ポインタ型を混同しないこと。関数型は、 通常はコンパイル時のリフレクションの目的で使用される。
Examples:property functionプロパティ関数class C { int value() @property => 0; static string opCall() => "hi"; } static assert(is( typeof(C.value) == int )); static assert(is( FunctionTypeOf!(C.value) == function )); static assert(is( FunctionTypeOf!C == typeof(C.opCall) )); int function() fp; alias IntFn = int(); static assert(is( typeof(fp) == IntFn* )); static assert(is( FunctionTypeOf!fp == IntFn ));
- template
SetFunctionAttributes
(T, string linkage, uint attrs) if (isFunctionPointer!T || isDelegate!T)
templateSetFunctionAttributes
(T, string linkage, uint attrs) if (is(T == function)) - 与えられたものと同じ基本シグネチャを持つが、異なる属性(リンクを含む)を持つ新しい関数またはデリゲート型を構築する。これは、実際の型名をすべて列挙することができない汎用コードにおいて、型への属性の追加/削除を行う際に特に有用である。Parameters:result type結果タイプ
T 基本型。 linkage 結果の型の望ましいリンク。 attrs 結果タイプの FunctionAttribute結果型の Examples:alias ExternC(T) = SetFunctionAttributes!(T, "C", functionAttributes!T); auto assumePure(T)(T t) if (isFunctionPointer!T || isDelegate!T) { enum attrs = functionAttributes!T | FunctionAttribute.pure_; return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t; } int f() { import core.thread : getpid; return getpid(); } int g() pure @trusted { auto pureF = assumePure(&f); return pureF(); } assert(g() > 0);
- template
isInnerClass
(T) if (is(T == class)) - T が別のクラス内にネストされたクラスであるかどうか、 およびT.outer が外側のクラスへの暗黙的な参照であるかどうかを決定する (すなわち、outer がフィールド名またはメソッド名として使用されていない)Parameters:
T テストする Returns: xml-ph-0000@deepl.internalが別のクラスにネストされたクラスであるかどうかを、前述の条件に基づいて xml-ph-0001@deepl.internal そうでない場合はxml-ph-0000@deepl.internalxml-ph-0001@deepl.internaltrue T が別のクラスにネストされたクラスであるかどうかを、前述の条件に基づいて テストする。 それ以外の場合falseExamples:class C { int outer; } static assert(!isInnerClass!C); class Outer1 { class Inner1 { } class Inner2 { int outer; } } static assert(isInnerClass!(Outer1.Inner1)); static assert(!isInnerClass!(Outer1.Inner2)); static class Outer2 { static class Inner { int outer; } } static assert(!isInnerClass!(Outer2.Inner));
- template
isNested
(T) if (is(T == class) || is(T == struct) || is(T == union)) - T が独自のコンテキストポインタを持っているかどうかを判断する。T は、class 、struct 、またはunion のいずれかでなければならない。こちらも参照: __traits(xml-ph-0002@deepl.internalxml-ph-0002@deepl.internal
isNested
, T)Examples:static struct S { } static assert(!isNested!S); int i; struct NestedStruct { void f() { ++i; } } static assert(isNested!NestedStruct);
- template
hasNested
(T) - T またはその表現型が コンテキストポインタを持つかどうかを判断する。to determine決定するExamples:構造体、クラス、またはユニオンのフィールドの型をタプルとして取得する。 これは、メモリ領域を占めるフィールドから構成され、 仮想関数テーブルポインタやネストされた型のためのコンテキストポインタなどの隠しフィールドは 除外される。
static struct S { } int i; struct NS { void f() { ++i; } } static assert(!hasNested!(S[2])); static assert(hasNested!(NS[2]));
- template
Fields
(T) - 構造体、クラス、または共用体のフィールドの型をタプルとして取得する。 これは、メモリ領域を占めるフィールドから構成され、 仮想関数テーブルポインタやネストされた型のためのコンテキストポインタのような隠されたフィールドは 除外される。T が構造体、クラス、インターフェース、または共用体でない場合、1つの要素を持つタプルを返す。T 。History:xml-ph-0000@deepl.internalxml-ph-0000@deepl.internal
- 2.097より前のインターフェース用のAliasSeq!(Interface) を返す
Examples:import std.meta : AliasSeq; struct S { int x; float y; } static assert(is(Fields!S == AliasSeq!(int, float)));
- alias
FieldTypeTuple
= Fields(T); - 代替名 Fields、レガシー互換性を保つために残されている。
- template
FieldNameTuple
(T) - 構造体、クラス、または共用体のフィールド名を式タプルとして取得する。 これは、メモリ領域を占めるフィールドから構成され、 仮想関数テーブルポインタやネスト型用のコンテキストポインタなどの隠しフィールドは 含まれない。 継承フィールド(クラス用)は含まれない。T が構造体、クラス、インターフェイス、または共用体でない場合、 空文字列の式タプルが返される。History:xml-ph-0000@deepl.internalxml-ph-0000@deepl.internal
- 2.097より前のインターフェース用のAliasSeq!"" が返される
Examples:import std.meta : AliasSeq; struct S { int x; float y; } static assert(FieldNameTuple!S == AliasSeq!("x", "y")); static assert(FieldNameTuple!int == AliasSeq!"");
- template
RepresentationTypeTuple
(T) - 構造体またはクラスのフィールドのプリミティブ型を、 位相順で取得する。topological order位相順Examples:xml-ph-0001@deepl.internal の表現に以下の少なくとも1つが含まれている場合のみ、xml-ph-0000@deepl.internal を返す。
struct S1 { int a; float b; } struct S2 { char[] a; union { S1 b; S1 * c; } } alias R = RepresentationTypeTuple!S2; assert(R.length == 4 && is(R[0] == char[]) && is(R[1] == int) && is(R[2] == float) && is(R[3] == S1*));
- enum auto
hasAliasing
(T...); - T の表現が以下の少なくとも1つを含む場合のみ、true を返す。interface typeインターフェースタイプ
- 生のポインタU* かつUが 不変ではない場合。
- 配列U[] およびU は 不変ではない。
- クラスまたはインターフェース型への参照C およびC は 不変ではない。
- 変更不可ではない連想配列。
- 代議員。
Examples:struct S1 { int a; Object b; } struct S2 { string a; } struct S3 { int a; immutable Object b; } struct S4 { float[3] vals; } static assert( hasAliasing!S1); static assert(!hasAliasing!S2); static assert(!hasAliasing!S3); static assert(!hasAliasing!S4);
- template
hasIndirections
(T) - Examples:
static assert( hasIndirections!(int[string])); static assert( hasIndirections!(void delegate())); static assert( hasIndirections!(void delegate() immutable)); static assert( hasIndirections!(immutable(void delegate()))); static assert( hasIndirections!(immutable(void delegate() immutable))); static assert(!hasIndirections!(void function())); static assert( hasIndirections!(void*[1])); static assert(!hasIndirections!(byte[1]));
- enum auto
hasUnsharedAliasing
(T...); - T の表現が以下のうち少なくともひとつを含む場合にのみ、true を返す。
- 生のポインタU* かつUが 不変または共有でない場合。
- 配列U[] およびU が 不変または共有ではない場合、
- クラス型への参照C およびC は不変でも共有でもない。
- 変更不可または共有ではない連想配列。
- 共有されていないデリゲート。
Examples:struct S1 { int a; Object b; } struct S2 { string a; } struct S3 { int a; immutable Object b; } static assert( hasUnsharedAliasing!S1); static assert(!hasUnsharedAliasing!S2); static assert(!hasUnsharedAliasing!S3); struct S4 { int a; shared Object b; } struct S5 { char[] a; } struct S6 { shared char[] b; } struct S7 { float[3] vals; } static assert(!hasUnsharedAliasing!S4); static assert( hasUnsharedAliasing!S5); static assert(!hasUnsharedAliasing!S6); static assert(!hasUnsharedAliasing!S7);
- template
hasElaborateCopyConstructor
(S) - S またはSの表現に直接埋め込まれた任意の型が 精巧なコピーコンストラクタを定義している場合は真。精巧なコピーコンストラクタは、this(this) をstruct に定義することで導入される。クラスおよび共用体は、決して精巧なコピーコンストラクタを持つことはない。
- template
hasElaborateAssign
(S) - S またはSの表現に直接埋め込まれた任意の型が 精巧な代入を定義している場合は真。精巧な代入は、 opAssign(typeof(this)) またはopAssign(ref typeof(this))を struct に定義した場合、またはコンパイラが生成したopAssign がある場合に型S は、精巧なデストラクタを持つ場合、コンパイラによって生成されたopAssign を取得する 。 クラスおよび共用体には、精巧な代入は決して存在しない。assignmentassignment
注釈 postblit 演算子(複数可)を持つ構造体には、 隠された複雑なコンパイラ生成の代入演算子が存在する( 明示的に無効化されていない限り)。
Examples:xml-ph-0000@deepl.internal または xml-ph-0001@deepl.internal の表現に直接埋め込まれた任意の型が 精巧なデストラクタを定義している場合は true。精巧なデストラクタstatic assert(!hasElaborateAssign!int); static struct S { void opAssign(S) {} } static assert( hasElaborateAssign!S); static assert(!hasElaborateAssign!(const(S))); static struct S1 { void opAssign(ref S1) {} } static struct S2 { void opAssign(int) {} } static struct S3 { S s; } static assert( hasElaborateAssign!S1); static assert(!hasElaborateAssign!S2); static assert( hasElaborateAssign!S3); static assert( hasElaborateAssign!(S3[1])); static assert(!hasElaborateAssign!(S3[0]));
- template
hasElaborateDestructor
(S) - S またはS の表現に直接埋め込まれた任意の型が 精巧なデストラクタを定義している場合は true。精巧なデストラクタは 、 struct に~this() を定義することで導入される。クラスや共用体は、たとえクラスが~this() を定義していても、決して精巧なデストラクタを持つことはない。
- template
hasElaborateMove
(S) - S またはSの表現に直接埋め込まれた任意の型が 精巧な移動セマンティクスを定義している場合は真。精巧な移動セマンティクスは、struct に対してopPostMove(ref typeof(this)) を定義することで導入される。クラスおよび共用体は、決して精巧な移動セマンティクスを持つことはない。
- enum auto
hasMember
(T, string name); - T が、name というシンボルを定義する集約である場合に限り、true を返す。deepldeeplExamples:
static assert(!hasMember!(int, "blah")); struct S1 { int blah; } struct S2 { int blah(){ return 0; } } class C1 { int blah; } class C2 { int blah(){ return 0; } } static assert(hasMember!(S1, "blah")); static assert(hasMember!(S2, "blah")); static assert(hasMember!(C1, "blah")); static assert(hasMember!(C2, "blah"));
- template
hasStaticMember
(T, string member) - 文字列memberで表されるシンボルが存在し、Tの静的メンバであるかどうか。Parameters:
T シンボルを含む型member 。 member T に存在するテスト対象のシンボルの名前。 Returns:0@deepl.internalxml-ph-0000@deepl.internaltrue member が存在し、静的である場合。Examples:static struct S { static void sf() {} void f() {} static int si; int i; } static assert( hasStaticMember!(S, "sf")); static assert(!hasStaticMember!(S, "f")); static assert( hasStaticMember!(S, "si")); static assert(!hasStaticMember!(S, "i")); static assert(!hasStaticMember!(S, "hello"));
- template
EnumMembers
(E) if (is(E == enum)) - 列挙型enum E のメンバを取得する。Parameters: 列挙型。xml-ph-0000@deepl.internal は重複した値を持つ可能性がある。
E 列挙型。E は重複した値を持つ可能性がある。 Returns:注 enum は同じ値を持つ複数のメンバーを持つことができる。 EnumMembers を使用して、例えばコンパイル時に switch ケースを生成したい場合は、 それを使用すべきである。列挙型のメンバで構成される静的タプルE 。 メンバは、E で宣言された順序で並べられる。 列挙型の名前は、コンパイラに識別子の名前を問い合わせることで確認できる。 すなわち、 __traits(identifier,EnumMembers
!MyEnum[i])。 値が一意である列挙については、 std.conv.toも使用できます。注 返される値は厳密に型付けされている。xml-ph-0000@deepl.internal。したがって、以下のコードは 明示的なキャストなしでは動作しない。注釈: 列挙型は、同じ値を持つ複数のメンバーを持つことができる。 EnumMembers を使用して、例えばコンパイル時に switch ケースを生成したい場合は、 std.meta.NoDuplicatesテンプレートを使用して、 重複するswitchケースが生成されないようにする。
注釈 戻り値は厳密に型付けされており、E 。したがって、以下のコードは 明示的なキャストなしでは動作しない。
enum E : int { a, b, c } int[] abc = cast(int[]) [ EnumMembers!E ];
変数の型が推測できる場合は、キャストは不要である。 以下の例を参照のこと。Examples:列挙された値の配列を作成するenum Sqrts : real { one = 1, two = 1.41421, three = 1.73205 } auto sqrts = [EnumMembers!Sqrts]; writeln(sqrts); // [Sqrts.one, Sqrts.two, Sqrts.three]
array配列Examples: 汎用関数 xml-ph-0000@deepl.internal の次の例では、このテンプレートを使用して、列挙型 xml-ph- のメンバ xml-ph-0001@deepl.internal を検索している。次の例における汎用関数rank(v) は、この テンプレートを使用して、列挙型E 内のメンバe を検索する。// eがEのi番目の列挙子であればiを返す。 static size_t rank(E)(E e) if (is(E == enum)) { static foreach (i, member; EnumMembers!E) { if (e == member) return i; } assert(0, "Not an enum member"); } enum Mode { read = 1, write = 2, map = 4 } writeln(rank(Mode.read)); // 0 writeln(rank(Mode.write)); // 1 writeln(rank(Mode.map)); // 2
xml-ph-0002@deepl.internalxml-ph-0002@deepl.internalExamples: EnumMembers を使用して、静的 foreach を使用する switch 文を生成する。このクラスまたはインターフェースのベースクラスおよびベースインターフェースの AliasSeq を取得する。 BaseTypeTuple!Object は、 空の型タプルを返す。EnumMembers を使用して、静的 foreach を使用する switch 文を生成する。import std.conv : to; class FooClass { string calledMethod; void foo() @safe { calledMethod = "foo"; } void bar() @safe { calledMethod = "bar"; } void baz() @safe { calledMethod = "baz"; } } enum FooEnum { foo, bar, baz } auto var = FooEnum.bar; auto fooObj = new FooClass(); s: final switch (var) { static foreach (member; EnumMembers!FooEnum) { case member: // 各列挙型の値に対してケースを生成する。 // fooObj.{列挙型の値名}()を呼び出す。 __traits(getMember, fooObj, to!string(member))(); break s; } } // FooEnum.barを渡すと、bar()メソッドが呼び出される。 writeln(fooObj.calledMethod); // "bar"
-ph-0001@deepl.internalEnumMembers - template
BaseTypeTuple
(A) - このクラスまたはインターフェイスのベースクラスおよびベースインターフェイスのAliasSeq を取得する。 BaseTypeTuple!Object は、 空の型タプルを返す。to generate返すExamples:
import std.meta : AliasSeq; interface I1 { } interface I2 { } interface I12 : I1, I2 { } static assert(is(BaseTypeTuple!I12 == AliasSeq!(I1, I2))); interface I3 : I1 { } interface I123 : I1, I2, I3 { } static assert(is(BaseTypeTuple!I123 == AliasSeq!(I1, I2, I3)));
- template
BaseClassesTuple
(T) if (is(T == class)) - このクラスのすべての基底クラスのエイリアスシーケンスを、 降順で取得する。インターフェイスは含まれない 。BaseClassesTuple!Objectは空の型タプルを返す。Examples:objectObject
import std.meta : AliasSeq; class C1 { } class C2 : C1 { } class C3 : C2 { } static assert(!BaseClassesTuple!Object.length); static assert(is(BaseClassesTuple!C1 == AliasSeq!(Object))); static assert(is(BaseClassesTuple!C2 == AliasSeq!(C1, Object))); static assert(is(BaseClassesTuple!C3 == AliasSeq!(C2, C1, Object)));
- template
InterfacesTuple
(T) - Parameters:
T class またはinterface を検索する。 Returns: このクラスまたはインターフェースが直接または間接的に継承するすべてのインターフェースを 検索する。インターフェースが複数回実装されている場合は、インターフェースは繰り返さない。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalxml-ph-0000@deepl.internalstd.meta.AliasSeqこのクラスまたはインターフェースが直接または間接的に継承しているすべてのインターフェースを 検索する。インターフェースは、 多重実装されている場合は繰り返さない。InterfacesTuple
!Objectは空のAliasSeq を生成する。Examples:interface I1 {} interface I2 {} class A : I1, I2 {} class B : A, I1 {} class C : B {} alias TL = InterfacesTuple!C; static assert(is(TL[0] == I1) && is(TL[1] == I2));
- template
TransitiveBaseTypeTuple
(T) - Tの すべての基本クラスのAliasSeqを降順で取得し、Tのインターフェースを続けたもの。 TransitiveBaseTypeTuple!Objectは、 空の型タプルを生成する。base class型タプルExamples:
interface J1 {} interface J2 {} class B1 {} class B2 : B1, J1, J2 {} class B3 : B2, J1 {} alias TL = TransitiveBaseTypeTuple!B3; writeln(TL.length); // 5 assert(is (TL[0] == B2)); assert(is (TL[1] == B1)); assert(is (TL[2] == Object)); assert(is (TL[3] == J1)); assert(is (TL[4] == J2)); writeln(TransitiveBaseTypeTuple!Object.length); // 0
- template
MemberFunctionsTuple
(C, string name) if (is(C == class) || is(C == interface)) - クラスまたはインターフェイスC で宣言された名前name を持つ非静的関数のタプルを返す。 派生したものに一致する場合は、共変の重複は最も派生したものに縮小される。covariantcovariantExamples:
interface I { I foo(); } class B { real foo(real v) { return v; } } class C : B, I { override C foo() { return this; } // I.foo()の共変オーバーライド } alias foos = MemberFunctionsTuple!(C, "foo"); static assert(foos.length == 2); static assert(__traits(isSame, foos[0], C.foo)); static assert(__traits(isSame, foos[1], B.foo));
- template
TemplateOf
(alias T : Base!Args, alias Base, Args...)
templateTemplateOf
(T : Base!Args, alias Base, Args...)
templateTemplateOf
(T) - T がインスタンスであるテンプレートのエイリアスを返す。 テンプレートを持たないシンボルが与えられた場合は、void を返す。to return返すExamples:
struct Foo(T, U) {} static assert(__traits(isSame, TemplateOf!(Foo!(int, real)), Foo));
- template
TemplateArgsOf
(alias T : Base!Args, alias Base, Args...)
templateTemplateArgsOf
(T : Base!Args, alias Base, Args...) - T のインスタンス化に使用されたテンプレート引数のAliasSeq を返す。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:
import std.meta : AliasSeq; struct Foo(T, U) {} static assert(is(TemplateArgsOf!(Foo!(int, real)) == AliasSeq!(int, real)));
- template
classInstanceAlignment
(T) if (is(T == class)) - クラスインスタンスの整列を返す。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:すべての型が暗黙的に変換できる型を取得する。 例えば、初期化値の集合から配列の型を把握する際に 役立つ。空のリストが渡された場合、または 型に共通の型がない場合は、voidを返す。
class A { byte b; } class B { long l; } // クラス・インスタンスは常に隠しポインタを持つので static assert(classInstanceAlignment!A == (void*).alignof); static assert(classInstanceAlignment!B == long.alignof);
- template
CommonType
(T...) - すべての型が暗黙的に変換できる型を取得する。 例えば、初期化値の集合から配列の型を把握する際に役立つ。 空のリストが渡された場合、あるいは 型に共通の型がない場合は、voidを返す。voidvoidExamples:voidvoid
alias X = CommonType!(int, long, short); assert(is(X == long)); alias Y = CommonType!(int, char[], short); assert(is(Y == void));
Examples:typetypestatic assert(is(CommonType!(3) == int)); static assert(is(CommonType!(double, 4, float) == double)); static assert(is(CommonType!(string, char[]) == const(char)[])); static assert(is(CommonType!(3, 3U) == uint)); static assert(is(CommonType!(double, int) == double));
- template
AllImplicitConversionTargets
(T) - Parameters:
T チェックする型 Returns:empty空std.meta.AliasSeq暗黙的な変換のすべての可能なターゲット型を持つ T 。 T がObject から派生したクラスである場合、 TransitiveBaseTypeTuple返されます。 型が組み込みの値型でも、Object から派生したクラスでもない場合、 空の std.meta.AliasSeq返されます。See Also:internalinternalExamples:import std.meta : AliasSeq; static assert(is(AllImplicitConversionTargets!(ulong) == AliasSeq!(long, float, double, real))); static assert(is(AllImplicitConversionTargets!(int) == AliasSeq!(dchar, uint, long, ulong, float, double, real))); static assert(is(AllImplicitConversionTargets!(float) == AliasSeq!(double, real))); static assert(is(AllImplicitConversionTargets!(double) == AliasSeq!(float, real))); static assert(is(AllImplicitConversionTargets!(char) == AliasSeq!(byte, ubyte, short, ushort, wchar, int, dchar, uint, long, ulong, float, double, real) )); static assert(is(AllImplicitConversionTargets!(wchar) == AliasSeq!( short, ushort, dchar, int, uint, long, ulong, float, double, real ))); static assert(is(AllImplicitConversionTargets!(dchar) == AliasSeq!( int, uint, long, ulong, float, double, real ))); static assert(is(AllImplicitConversionTargets!(string) == AliasSeq!(const(char)[]))); static assert(is(AllImplicitConversionTargets!(int*) == AliasSeq!(void*))); interface A {} interface B {} class C : A, B {} static assert(is(AllImplicitConversionTargets!(C) == AliasSeq!(Object, A, B))); static assert(is(AllImplicitConversionTargets!(const C) == AliasSeq!(const Object, const A, const B))); static assert(is(AllImplicitConversionTargets!(immutable C) == AliasSeq!( immutable Object, immutable A, immutable B ))); interface I : A, B {} static assert(is(AllImplicitConversionTargets!(I) == AliasSeq!(A, B))); static assert(is(AllImplicitConversionTargets!(const I) == AliasSeq!(const A, const B))); static assert(is(AllImplicitConversionTargets!(immutable I) == AliasSeq!( immutable A, immutable B )));
- template
ImplicitConversionTargets
(T) - Parameters:
T 確認する型 警告 このテンプレートは旧式と見なされている。 2.107.0で"phobos"から削除される予定である。 AllImplicitConversionTargets代わりに
Returns:std.meta.AliasSeq暗黙の変換のすべての可能な対象型を持つ T 。 T がObject から派生したクラスである場合、 TransitiveBaseTypeTuple返されます。 型が組み込みの値型でも、Object から派生したクラスでもない場合、 空の std.meta.AliasSeqが返されます。注釈: 可能なターゲットは、言語が許容するよりも保守的に計算され、 危険な変換はすべて排除される。例えば、
ImplicitConversionTargets
!doublefloat は含まれません。See Also: - enum bool
isImplicitlyConvertible
(From, To); - From は暗黙的にTo に変換可能か?xml-ph-0000@deepl.internalxml-ph-0001@deepl.internalExamples:xml-ph-0000@deepl.internal は xml-ph-0001@deepl.internal に暗黙的に変換可能か?
static assert( isImplicitlyConvertible!(immutable(char), char)); static assert( isImplicitlyConvertible!(const(char), char)); static assert( isImplicitlyConvertible!(char, wchar)); static assert(!isImplicitlyConvertible!(wchar, char)); static assert(!isImplicitlyConvertible!(const(ushort), ubyte)); static assert(!isImplicitlyConvertible!(const(uint), ubyte)); static assert(!isImplicitlyConvertible!(const(ulong), ubyte)); static assert(!isImplicitlyConvertible!(const(char)[], string)); static assert( isImplicitlyConvertible!(string, const(char)[]));
- enum bool
isQualifierConvertible
(From, To); - xml-ph-0001@deepl.internalxml-ph-0001@deepl.internalExamples:xml-ph-0000@deepl.internal を返すのは、xml-ph-0001@deepl.internal 型の値が xml-ph-0002 型の変数に
// Mutableもimmmutableもconstに変換される... static assert( isQualifierConvertible!(char, const(char))); static assert( isQualifierConvertible!(immutable(char), const(char))); // ...しかし、constはmutableにもimmutableにも変換しない static assert(!isQualifierConvertible!(const(char), char)); static assert(!isQualifierConvertible!(const(char), immutable(char)));
- enum auto
isAssignable
(Lhs, Rhs = Lhs); - Rhs 型の値がLhs 型の変数に代入できる場合にのみ、true を返す。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internal
isAssignable
"l値"と"r値"の両方が代入可能であるかどうかを返す。 Rhs を省略すると、isAssignable
Lhs の同一性代入が可能かどうかをチェックします。Examples:xml-ph-0001@deepl.internal型の右辺値がxml-ph-000型の変数に代入できる場合に限り、xml-ph-0000@deepl.internalを返すstatic assert( isAssignable!(long, int)); static assert(!isAssignable!(int, long)); static assert( isAssignable!(const(char)[], string)); static assert(!isAssignable!(string, char[])); // intはintに代入できる static assert( isAssignable!int); // immutable intはimmutable intに代入できない static assert(!isAssignable!(immutable int));
- enum auto
isRvalueAssignable
(Lhs, Rhs = Lhs); - Rhs 型のr値がLhs 型の変数に代入できる場合にのみ、true を返す。xml-ph-0002@deepl.internalxml-ph-0002@deepl.internalExamples:
struct S1 { void opAssign(S1); } struct S2 { void opAssign(ref S2); } static assert( isRvalueAssignable!(long, int)); static assert(!isRvalueAssignable!(int, long)); static assert( isRvalueAssignable!S1); static assert(!isRvalueAssignable!S2);
- enum auto
isLvalueAssignable
(Lhs, Rhs = Lhs); - true を返す。Rhs 型の lvalue がLhs 型の変数に代入できる場合。xml-ph-0001@deepl.internalxml-ph-0002@deepl.internalExamples:
struct S1 { void opAssign(S1); } struct S2 { void opAssign(ref S2); } static assert( isLvalueAssignable!(long, int)); static assert(!isLvalueAssignable!(int, long)); static assert( isLvalueAssignable!S1); static assert( isLvalueAssignable!S2);
- template
isCovariantWith
(F, G) if (is(F == function) && is(G == function) || is(F == delegate) && is(G == delegate) || isFunctionPointer!F && isFunctionPointer!G) - 関数型F がG と共変であるかどうか、すなわち、F の型を持つ関数がG の型を持つ関数をオーバーライドできるかどうかを決定する。xml-ph-0002@deepl.internalxml-ph-0002@deepl.internalExamples:xml-ph-0001@deepl.internal に対して xml-ph-0000@deepl.internal 型の左辺値または右辺値を作成し、
interface I { I clone(); } interface J { J clone(); } class C : I { override C clone() // I.clone()の共変オーバーライド { return new C; } } // C.clone()は、確かにI.clone()を上書きすることができる。 static assert(isCovariantWith!(typeof(C.clone), typeof(I.clone))); // C.clone()はJ.clone()を上書きできない; 戻り値の型Cは暗黙的に // Jに変換できない。 static assert(!isCovariantWith!(typeof(C.clone), typeof(J.clone)));
- @property T
rvalueOf
(T)(inout __InoutWorkaroundStruct = __InoutWorkaroundStruct.init);
@property ref TlvalueOf
(T)(inout __InoutWorkaroundStruct = __InoutWorkaroundStruct.init); - Parameters:注 返された値を使用しようとすると、 リンク時に「シンボル未定義」エラーが発生する。
T 変換される型は 注釈 返された値を使用しようとすると、 リンク時に「シンボル未定義」エラーが発生する。
Examples:typetypestatic int f(int); static assert(is(typeof(f(rvalueOf!int)) == int));
Examples:symbol undefinedSymbol Undefinedstatic bool f(ref int); static assert(is(typeof(f(lvalueOf!int)) == bool));
- enum bool
isBoolean
(T); - T が組み込みのブーリアン型であるか、ブーリアン基本型の列挙型であるかを検出する。Examples:
static assert( isBoolean!bool); enum EB : bool { a = true } static assert( isBoolean!EB); struct SubTypeOfBool { bool val; alias val this; } static assert(!isBoolean!(SubTypeOfBool));
- template
isIntegral
(T) - T が組み込みの整数型であるかどうかを検出する。 整数型は、byte 、ubyte 、short 、ushort 、int 、uint 、long 、ulong 、cent 、ucent 、 および、整数型を基本型とする列挙型である。Parameters:
T 型をテストする Returns: xml-ph-0000@deepl.internal が整数型であるかどうかを注意 これは、整数型とは異なる。true T が整数型であるかどうかをif注釈 これは、xml-ph-0000@deepl.internal が整数型であるかどうかをテストするものであり、xml-ph-0000@deepl.internal が整数型であるかどうかをテストするものではない。 __traits(
isIntegral
)Examples:xml-ph-0000@deepl.internal が組み込みの浮動小数点型であるかどうかを検出する。static assert( isIntegral!byte && isIntegral!short && isIntegral!int && isIntegral!long && isIntegral!(const(long)) && isIntegral!(immutable(long)) ); static assert( !isIntegral!bool && !isIntegral!char && !isIntegral!double ); // 整数として機能する型は渡さない struct S { int val; alias val this; } static assert(!isIntegral!S);
- enum bool
isFloatingPoint
(T); - T が組み込み浮動小数点型であるかどうかを検出する。to detect検出Examples:
static assert( isFloatingPoint!float && isFloatingPoint!double && isFloatingPoint!real && isFloatingPoint!(const(real)) && isFloatingPoint!(immutable(real)) ); static assert(!isFloatingPoint!int); // 浮動小数点値として機能する型は渡さない struct S { float val; alias val this; } static assert(!isFloatingPoint!S);
- template
isNumeric
(T) - T が組み込みの数値型(整数または浮動小数点数)であるかどうかを検出する。built-in組み込みExamples:
static assert( isNumeric!byte && isNumeric!short && isNumeric!int && isNumeric!long && isNumeric!float && isNumeric!double && isNumeric!real && isNumeric!(const(real)) && isNumeric!(immutable(real)) ); static assert( !isNumeric!void && !isNumeric!bool && !isNumeric!char && !isNumeric!wchar && !isNumeric!dchar ); // 数値として機能する型は渡さない struct S { int val; alias val this; } static assert(!isNumeric!S);
- enum bool
isScalarType
(T); - T がスカラー型(組み込みの数値型、文字型、または ブーリアン型)であるかどうかを検出する。to see also参照Examples:
static assert(!isScalarType!void); static assert( isScalarType!(immutable(byte))); static assert( isScalarType!(immutable(ushort))); static assert( isScalarType!(immutable(int))); static assert( isScalarType!(ulong)); static assert( isScalarType!(shared(float))); static assert( isScalarType!(shared(const bool))); static assert( isScalarType!(const(char))); static assert( isScalarType!(wchar)); static assert( isScalarType!(const(dchar))); static assert( isScalarType!(const(double))); static assert( isScalarType!(const(real)));
- enum bool
isBasicType
(T); - T が基本型(スカラ型またはvoid)であるかどうかを検出する。scalar typescalar typeExamples:
static assert(isBasicType!void); static assert(isBasicType!(const(void))); static assert(isBasicType!(shared(void))); static assert(isBasicType!(immutable(void))); static assert(isBasicType!(shared const(void))); static assert(isBasicType!(shared inout(void))); static assert(isBasicType!(shared inout const(void))); static assert(isBasicType!(inout(void))); static assert(isBasicType!(inout const(void))); static assert(isBasicType!(immutable(int))); static assert(isBasicType!(shared(float))); static assert(isBasicType!(shared(const bool))); static assert(isBasicType!(const(dchar)));
- template
isUnsigned
(T) - T が組み込みの符号なし数値型であるかどうかを検出する。scalar type数値型Examples:
static assert( isUnsigned!uint && isUnsigned!ulong ); static assert( !isUnsigned!char && !isUnsigned!int && !isUnsigned!long && !isUnsigned!char && !isUnsigned!wchar && !isUnsigned!dchar );
- enum bool
isSigned
(T); - T が組み込みの符号付き数値型であるかどうかを検出する。built-in組み込みExamples:
static assert( isSigned!int && isSigned!long ); static assert( !isSigned!uint && !isSigned!ulong );
- template
isSomeChar
(T) - T が組み込み文字型の一つであるかどうかを検出する。組み込みの文字型は、char 、wchar 、dchar のいずれかであり、 修飾子を伴う場合と伴わない場合がある。Examples:
//文字型 static assert( isSomeChar!char); static assert( isSomeChar!wchar); static assert( isSomeChar!dchar); static assert( isSomeChar!(typeof('c'))); static assert( isSomeChar!(immutable char)); static assert( isSomeChar!(const dchar)); //非文字型 static assert(!isSomeChar!int); static assert(!isSomeChar!byte); static assert(!isSomeChar!string); static assert(!isSomeChar!wstring); static assert(!isSomeChar!dstring); static assert(!isSomeChar!(char[4]));
- enum bool
isSomeString
(T); - T が組み込み文字列型であるかどうかを検出する。組み込みの文字列型は、Char[] であり、Char は、修飾子付きまたは修飾子なしの、char 、wchar 、またはdchar のいずれかである。 文字の静的配列(char[80] のような)は、 組み込みの文字列型とはみなされない。Examples:
//文字列型 static assert( isSomeString!string); static assert( isSomeString!(wchar[])); static assert( isSomeString!(dchar[])); static assert( isSomeString!(typeof("aaa"))); static assert( isSomeString!(const(char)[])); //非文字列型 static assert(!isSomeString!int); static assert(!isSomeString!(int[])); static assert(!isSomeString!(byte[])); static assert(!isSomeString!(typeof(null))); static assert(!isSomeString!(char[4])); enum ES : string { a = "aaa", b = "bbb" } static assert(!isSomeString!ES); static struct Stringish { string str; alias str this; } static assert(!isSomeString!Stringish);
- enum bool
isNarrowString
(T); - 型T がナロー文字列であるかどうかを検出する。char、wchar、およびそれらの修飾バージョンを使用するすべての配列は、ナロー文字列である。 (これにはstringおよびwstringが含まれる)。narrow stringnarrow stringExamples:xml-ph-0000@deepl.internal が比較可能な型であるかどうかを検出する。基本型および構造体、 opCmp を実装するクラスは、順序比較可能である。
static assert(isNarrowString!string); static assert(isNarrowString!wstring); static assert(isNarrowString!(char[])); static assert(isNarrowString!(wchar[])); static assert(!isNarrowString!dstring); static assert(!isNarrowString!(dchar[])); static assert(!isNarrowString!(typeof(null))); static assert(!isNarrowString!(char[4])); enum ES : string { a = "aaa", b = "bbb" } static assert(!isNarrowString!ES); static struct Stringish { string str; alias str this; } static assert(!isNarrowString!Stringish);
- enum bool
isOrderingComparable
(T);
enum boolisEqualityComparable
(T); - T が比較可能な型であるかどうかを検出する。基本型および構造体、 opCmp を実装するクラスは、順序比較が可能である。typetypeExamples:
static assert(isOrderingComparable!int); static assert(isOrderingComparable!string); static struct Foo {} static assert(!isOrderingComparable!Foo); static struct Bar { int a; auto opCmp(Bar b1) const { return a - b1.a; } } Bar b1 = Bar(5); Bar b2 = Bar(7); assert(isOrderingComparable!Bar && b2 > b1);
- enum auto
isConvertibleToString
(T); - 警告: このトレイトは、"phobos"で使用されなくなったらすぐに非推奨となる。 関数パラメータが、暗黙的に文字列に変換される型を安全に文字列として受け入れるには、 変換は呼び出し側で実行する必要がある。そうでないと、変換は 関数内部で実行され、多くの場合、 ローカルメモリがスライスされることになる(例えば、静的配列が関数に渡されると、それがコピーされ、結果として得られる動的 コピーされ、結果として得られる動的 配列はローカル変数のスライスとなる)。つまり、 結果として得られる文字列が関数からエスケープされる場合、その文字列は 無効なメモリを参照し、そのメモリにアクセスすることは無効なメモリにアクセスする ことを意味する。そのため、関数が文字列に暗黙的に変換される型を受け入れる唯一の安全な方法は、 変換が呼び出し側で行われるようにすることであり、 パラメータが明示的に配列として型付けされている場合のみ可能である。一方、 テンプレート制約でisConvertibleToStringを使用すると、 変換が関数内部で行われることになる。 そのため、isConvertibleToStringは本質的に安全ではなく、T が暗黙的に文字列に変換可能な構造体、静的配列、または列挙型であるかどうかを検出する 。enumenumExamples:
static struct AliasedString { string s; alias s this; } enum StringEnum { a = "foo" } assert(!isConvertibleToString!string); assert(isConvertibleToString!AliasedString); assert(isConvertibleToString!StringEnum); assert(isConvertibleToString!(char[25])); assert(!isConvertibleToString!(char[]));
- enum auto
isAutodecodableString
(T); - 型T が自動デコードされる文字列であるかどうかを検出する。型S が以下のいずれかである場合:
- const(char)[]
- const(wchar)[]
- S
- 暗黙的にベースタイプを持つ列挙型に変換できるT
- 基本型を持つ列挙型T
- ベース型を持つ集約型T
Parameters:T 型をテストする Returns: T がオートデコードの対象となる文字列を表している場合は true xml-ph-0000@deepl.internal 関連項目:see also参照Tがオートデコードの対象となる文字列を表す場合はtrue 関連情報: isNarrowStringExamples:static struct Stringish { string s; alias s this; } static assert(isAutodecodableString!wstring); static assert(isAutodecodableString!Stringish); static assert(!isAutodecodableString!dstring); enum E : const(char)[3] { X = "abc" } enum F : const(char)[] { X = "abc" } enum G : F { X = F.init } static assert(isAutodecodableString!(char[])); static assert(!isAutodecodableString!(E)); static assert(isAutodecodableString!(F)); static assert(isAutodecodableString!(G)); struct Stringish2 { Stringish s; alias s this; } enum H : Stringish { X = Stringish() } enum I : Stringish2 { X = Stringish2() } static assert(isAutodecodableString!(H)); static assert(isAutodecodableString!(I)); static assert(!isAutodecodableString!(noreturn[])); static assert(!isAutodecodableString!(immutable(noreturn)[]));
- enum bool
isStaticArray
(T); - T が静的配列であるかどうかを検出する。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:
static assert( isStaticArray!(int[3])); static assert( isStaticArray!(const(int)[5])); static assert( isStaticArray!(const(int)[][5])); static assert(!isStaticArray!(const(int)[])); static assert(!isStaticArray!(immutable(int)[])); static assert(!isStaticArray!(const(int)[4][])); static assert(!isStaticArray!(int[])); static assert(!isStaticArray!(int[char])); static assert(!isStaticArray!(int[1][])); static assert(!isStaticArray!(int[int])); static assert(!isStaticArray!int);
- template
isDynamicArray
(T) - T 型が動的配列であるかどうかを検出する。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:
static assert( isDynamicArray!(int[])); static assert( isDynamicArray!(string)); static assert( isDynamicArray!(long[3][])); static assert(!isDynamicArray!(int[5])); static assert(!isDynamicArray!(typeof(null)));
- enum bool
isArray
(T); - 型T が配列(静的または動的)であるかどうかを検出する( 連想配列については isAssociativeArray。dynamic array動的配列Examples:
static assert( isArray!(int[])); static assert( isArray!(int[5])); static assert( isArray!(string)); static assert(!isArray!uint); static assert(!isArray!(uint[uint])); static assert(!isArray!(typeof(null)));
- enum bool
isAssociativeArray
(T); - T が連想配列型であるかどうかを検出するto detect参照Examples:
struct S; static assert( isAssociativeArray!(int[string])); static assert( isAssociativeArray!(S[S])); static assert(!isAssociativeArray!(string[])); static assert(!isAssociativeArray!S); static assert(!isAssociativeArray!(int[4]));
- enum bool
isBuiltinType
(T); - T が組み込み型であるかどうかを検出する。typetypeExamples:
class C; union U; struct S; interface I; static assert( isBuiltinType!void); static assert( isBuiltinType!string); static assert( isBuiltinType!(int[])); static assert( isBuiltinType!(C[string])); static assert( isBuiltinType!(typeof(null))); static assert(!isBuiltinType!C); static assert(!isBuiltinType!U); static assert(!isBuiltinType!S); static assert(!isBuiltinType!I); static assert(!isBuiltinType!(void delegate(int)));
- enum bool
isSIMDVector
(T); - 型T がSIMDベクトル型であるかどうかを検出する。SIMD vector typeSIMDベクトル型Examples:
static if (is(__vector(float[4]))) { alias SimdVec = __vector(float[4]); static assert(isSIMDVector!(__vector(float[4]))); static assert(isSIMDVector!SimdVec); } static assert(!isSIMDVector!uint); static assert(!isSIMDVector!(float[4]));
- enum bool
isPointer
(T); - 型T がポインタであるかどうかを検出する。Examples:xml-ph-0000@deepl.internalxml-ph-0000@deepl.internal
void fun(); static assert( isPointer!(int*)); static assert( isPointer!(int function())); static assert(!isPointer!int); static assert(!isPointer!string); static assert(!isPointer!(typeof(null))); static assert(!isPointer!(typeof(fun))); static assert(!isPointer!(int delegate()));
- template
PointerTarget
(T : T*) - ポインタのターゲット型を返す。Examples:
static assert(is(PointerTarget!(int*) == int)); static assert(is(PointerTarget!(void*) == void));
- enum bool
isAggregateType
(T); - 型T が集合型であるかどうかを検出する。Examples:
class C; union U; struct S; interface I; static assert( isAggregateType!C); static assert( isAggregateType!U); static assert( isAggregateType!S); static assert( isAggregateType!I); static assert(!isAggregateType!void); static assert(!isAggregateType!string); static assert(!isAggregateType!(int[])); static assert(!isAggregateType!(C[string])); static assert(!isAggregateType!(void delegate(int)));
- enum bool
isIterable
(T); - foreach ループを使用してTを反復処理できる場合、自動的に推論された型を持つ単一のループ変数を使用して、true を返す。foreach ループがどのように実装されているかは問わない。これには、範囲、 単一のループ変数でopApply を定義する構造体/クラス、および組み込みの動的、 静的、連想配列が含まれる。internal loop内部ループExamples:
struct OpApply { int opApply(scope int delegate(ref uint) dg) { assert(0); } } struct Range { @property uint front() { assert(0); } void popFront() { assert(0); } enum bool empty = false; } static assert( isIterable!(uint[])); static assert( isIterable!OpApply); static assert( isIterable!(uint[string])); static assert( isIterable!Range); static assert(!isIterable!uint);
- enum bool
isMutable
(T); - Tがconstまたはimmutableでない場合はtrueを返す。isMutableは、 stringまたはimmutable(char[])に対してはtrueとなる。これは、'head'が変更可能であるためである。mutable可変Examples:
static assert( isMutable!int); static assert( isMutable!string); static assert( isMutable!(shared int)); static assert( isMutable!(shared const(int)[])); static assert(!isMutable!(const int)); static assert(!isMutable!(inout int)); static assert(!isMutable!(shared(const int))); static assert(!isMutable!(shared(inout int))); static assert(!isMutable!(immutable string));
- enum bool
isInstanceOf
(alias S, T);
enum autoisInstanceOf
(alias S, alias T); - T がテンプレート S のインスタンスである場合、true を返す。truetrueExamples:
static struct Foo(T...) { } static struct Bar(T...) { } static struct Doo(T) { } static struct ABC(int x) { } static void fun(T)() { } template templ(T) { } static assert(isInstanceOf!(Foo, Foo!int)); static assert(!isInstanceOf!(Foo, Bar!int)); static assert(!isInstanceOf!(Foo, int)); static assert(isInstanceOf!(Doo, Doo!int)); static assert(isInstanceOf!(ABC, ABC!1)); static assert(!isInstanceOf!(Foo, Foo)); static assert(isInstanceOf!(fun, fun!int)); static assert(isInstanceOf!(templ, templ!int));
Examples:タプル T が式タプルであるかどうかを確認する。 式タプルには式のみが含まれる。isInstanceOf
テンプレート内部でテンプレートの同一性を確認するには、 使用する。 TemplateOf。static struct A(T = void) { // 期待通りには働かず、T = voidの時のみAを受け付ける void func(B)(B b) if (isInstanceOf!(A, B)) {} // 正しい動作 void method(B)(B b) if (isInstanceOf!(TemplateOf!(A), B)) {} } A!(void) a1; A!(void) a2; A!(int) a3; static assert(!__traits(compiles, a1.func(a3))); static assert( __traits(compiles, a1.method(a2))); static assert( __traits(compiles, a1.method(a3)));
to use使用する - template
isExpressions
(T...) - タプル T が式タプルであるかどうかを確認する。 式タプルには式のみが含まれる。See Also: 。expression tuple表現タプルExamples:
static assert(isExpressions!(1, 2.0, "a")); static assert(!isExpressions!(int, double, string)); static assert(!isExpressions!(int, 2.0, "a"));
- alias
isExpressionTuple
= isExpressions(T...); - 別名 isExpressions、レガシーとの互換性を保つために残されている。
- enum auto
isTypeTuple
(T...); - タプルT が型タプルであるかどうかを確認する。 型タプルには型のみが含まれる。See Also:type tuple型タプルExamples:
static assert(isTypeTuple!(int, float, string)); static assert(!isTypeTuple!(1, 2.0, "a")); static assert(!isTypeTuple!(1, double, string));
- enum bool
isFunctionPointer
(alias T); - シンボルまたは型T が関数ポインタであるかどうかを検出する。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:
static void foo() {} void bar() {} auto fpfoo = &foo; static assert( isFunctionPointer!fpfoo); static assert( isFunctionPointer!(void function())); auto dgbar = &bar; static assert(!isFunctionPointer!dgbar); static assert(!isFunctionPointer!(void delegate())); static assert(!isFunctionPointer!foo); static assert(!isFunctionPointer!bar); static assert( isFunctionPointer!((int a) {}));
- enum bool
isDelegate
(alias T); - シンボルまたは型T がデリゲートであるかどうかを検出する。typetypeExamples:
static void sfunc() { } int x; void func() { x++; } int delegate() dg; assert(isDelegate!dg); assert(isDelegate!(int delegate())); assert(isDelegate!(typeof(&func))); int function() fp; assert(!isDelegate!fp); assert(!isDelegate!(int function())); assert(!isDelegate!(typeof(&sfunc)));
- enum bool
isSomeFunction
(alias T); - シンボルまたは型T が関数、関数ポインタ、またはデリゲートであるかどうかを検出する。Parameters:
T 確認する型は Returns: Atype種類AboolExamples:xml-ph-0000@deepl.internal が呼び出し可能なオブジェクトであるかどうかを検出する。これは、 関数呼び出し演算子xml-ph-0001@deepl.internalで呼び出すことができる。static real func(ref int) { return 0; } static void prop() @property { } class C { real method(ref int) { return 0; } real prop() @property { return 0; } } auto c = new C; auto fp = &func; auto dg = &c.method; static assert( isSomeFunction!func); static assert( isSomeFunction!prop); static assert( isSomeFunction!(C.method)); static assert( isSomeFunction!(C.prop)); static assert( isSomeFunction!(c.prop)); static assert( isSomeFunction!fp); static assert( isSomeFunction!dg); real val; static assert(!isSomeFunction!int); static assert(!isSomeFunction!val);
- template
isCallable
(alias callable) - T が呼び出し可能なオブジェクトであるかどうかを検出し、 関数呼び出し演算子(...) で呼び出すことができる。Examples: 関数、ラムダ式、および(静的)opCallを持つ集約型。(static) opCall を使用した関数、ラムダ、集約型。
void f() { } int g(int x) { return x; } static assert( isCallable!f); static assert( isCallable!g); class C { int opCall(int) { return 0; } } auto c = new C; struct S { static int opCall(int) { return 0; } } interface I { real value() @property; } static assert( isCallable!c); static assert( isCallable!(c.opCall)); static assert( isCallable!S); static assert( isCallable!(I.value)); static assert( isCallable!((int a) { return a; })); static assert(!isCallable!I);
opCallopCallExamples: テンプレートテンプレートvoid f()() { } T g(T = int)(T x) { return x; } struct S1 { static void opCall()() { } } struct S2 { static T opCall(T = int)(T x) {return x; } } static assert( isCallable!f); static assert( isCallable!g); static assert( isCallable!S1); static assert( isCallable!S2);
templateテンプレートExamples: オーバーロードされた関数と関数テンプレート。オーバーロードされた関数および関数テンプレート。static struct Wrapper { void f() { } int f(int x) { return x; } void g()() { } T g(T = int)(T x) { return x; } } static assert(isCallable!(Wrapper.f)); static assert(isCallable!(Wrapper.g));
templateテンプレート - enum auto
isAbstractFunction
(alias S); - S が抽象関数であるかどうかを検出する。参照: __traits(xml-ph-0000@deepl.internalxml-ph-0000@deepl.internal
isAbstractFunction
, S) functionfunctionParameters:S 確認するシンボル Returns:symbol記号AboolExamples:xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalstruct S { void foo() { } } class C { void foo() { } } class AC { abstract void foo(); } static assert(!isAbstractFunction!(int)); static assert(!isAbstractFunction!(S.foo)); static assert(!isAbstractFunction!(C.foo)); static assert( isAbstractFunction!(AC.foo));
- enum auto
isFinalFunction
(alias S); - S が最終関数であるかどうかを検出する。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:
struct S { void bar() { } } final class FC { void foo(); } class C { void bar() { } final void foo(); } static assert(!isFinalFunction!(int)); static assert(!isFinalFunction!(S.bar)); static assert( isFinalFunction!(FC.foo)); static assert(!isFinalFunction!(C.bar)); static assert( isFinalFunction!(C.foo));
- enum auto
isNestedFunction
(alias f); - f がコンテキストポインタを必要とする関数であるかどうかを判断する。Parameters:to determine確認する
f 確認する型 戻り値 Abool Examples:xml-ph-0000@deepl.internal が抽象クラスであるかどうかを検出する。static void f() {} static void fun() { int i; int f() { return i; } static assert(isNestedFunction!(f)); } static assert(!isNestedFunction!f);
- enum auto
isAbstractClass
(alias S); - S が抽象クラスであるかどうかを検出する。to check検出Examples:
struct S { } class C { } abstract class AC { } static assert(!isAbstractClass!S); static assert(!isAbstractClass!C); static assert( isAbstractClass!AC); C c; static assert(!isAbstractClass!c); AC ac; static assert( isAbstractClass!ac);
- enum auto
isFinalClass
(alias S); - S が final クラスであるかどうかを検出する。alsoもExamples:
class C { } abstract class AC { } final class FC1 : C { } final class FC2 { } static assert(!isFinalClass!C); static assert(!isFinalClass!AC); static assert( isFinalClass!FC1); static assert( isFinalClass!FC2); C c; static assert(!isFinalClass!c); FC1 fc1; static assert( isFinalClass!fc1);
- template
Unconst
(T) - const 、inout 、immutable の修飾子(もしあれば)を型T から削除する。
- template
Unshared
(T) - shared 修飾子(もしあれば)をT から削除する。immutable は暗黙的にshared であるが、Unshared には影響されないことに注意。 削除されるのは明示的なshared のみである。xml-ph-0002@deepl.internalxml-ph-0002@deepl.internalExamples:
static assert(is(Unshared!int == int)); static assert(is(Unshared!(const int) == const int)); static assert(is(Unshared!(immutable int) == immutable int)); static assert(is(Unshared!(shared int) == int)); static assert(is(Unshared!(shared(const int)) == const int)); static assert(is(Unshared!(shared(int[])) == shared(int)[]));
- template
Unqual
(T) - もしあれば、型T からすべての修飾子を削除する。
- template
CopyTypeQualifiers
(FromType, ToType) - FromType からToType に型修飾子をコピーする。サポートされている型修飾子:type qualifierタイプ修飾子
- const
- inout
- immutable
- shared
Examples:xml-ph-0000@deepl.internal の型を、xml-ph-0001@deepl.internal の「constness」とともに返す。型のxml-ph-0002static assert(is(CopyTypeQualifiers!(inout const real, int) == inout const int));
- template
CopyConstness
(FromType, ToType) - ToType の型を、FromType の「constness」とともに返す。型のconstnessは、 それがconst 、immutable 、またはinout のいずれであるかを指す。FromType にconstnessがない場合、 返される型はToType と同じになる。xml-ph-0007@deepl.internalxml-ph-0007@deepl.internalExamples:
const(int) i; CopyConstness!(typeof(i), float) f; assert( is(typeof(f) == const float)); CopyConstness!(char, uint) u; assert( is(typeof(u) == uint)); //'shared'修飾子はコピーされない assert(!is(CopyConstness!(shared bool, int) == shared int)); //しかし、定数は assert( is(CopyConstness!(shared const real, double) == const double)); //注意、const(int)[]はconst(int)の変更可能配列である alias MutT = CopyConstness!(const(int)[], int); assert(!is(MutT == const(int))); //OK、const(int[])は配列と含まれるintに適用される alias CstT = CopyConstness!(const(int[]), int); assert( is(CstT == const(int)));
- template
ForeachType
(T) - 型 T の変数がforeach ループで単一のループ変数を使用して反復処理され、自動的に推論された戻り値の型である場合、ループ変数の推論された型を返す。 これは、狭義の文字列の場合や、T が opApply と範囲インターフェースの両方を持つ場合、std.range.ElementType!Range と同じではない可能性があることに注意。xml-ph-0001@deepl.internalxml-ph-0001@deepl.internalExamples:
static assert(is(ForeachType!(uint[]) == uint)); static assert(is(ForeachType!string == immutable(char))); static assert(is(ForeachType!(string[string]) == string)); static assert(is(ForeachType!(inout(int)[]) == inout(int)));
- template
OriginalType
(T) - 型T からenumをすべて取り除く。xml-ph-0000@deepl.internalxml-ph-0001@deepl.internalExamples:
enum E : real { a = 0 } // 注釈: Enum initの非推奨サイクルでは、明示的に0に初期化する必要がある enum F : E { a = E.a } alias G = const(F); static assert(is(OriginalType!E == real)); static assert(is(OriginalType!F == real)); static assert(is(OriginalType!G == const real));
- template
KeyType
(V : V[K], K) - 連想配列のキーの型を取得する。xml-ph-0000@deepl.internalxml-ph-0000@deepl.internalExamples:
alias Hash = int[string]; static assert(is(KeyType!Hash == string)); static assert(is(ValueType!Hash == int)); KeyType!Hash str = "a"; // strは文字列として宣言される ValueType!Hash num = 1; // numはintとして宣言される
- template
ValueType
(V : V[K], K) - 連想配列の値の型を取得する。to get取得Examples:to getGet
alias Hash = int[string]; static assert(is(KeyType!Hash == string)); static assert(is(ValueType!Hash == int)); KeyType!Hash str = "a"; // strは文字列として宣言される ValueType!Hash num = 1; // numはintとして宣言される
- template
Unsigned
(T) - Parameters:
T 組み込みの整数型またはベクトル型。 Returns: xml-ph-0000@deepl.internalに対応する符号なし数値型で、同じ型修飾子を持つ。xml-ph-0001@deepl.internal xml-phT に対応する符号なし数値型で、 同じ型修飾子を持つ。 T が整数型またはベクトル型でない場合、コンパイル時にエラーが発生する。Examples:static assert(is(Unsigned!(int) == uint)); static assert(is(Unsigned!(long) == ulong)); static assert(is(Unsigned!(const short) == const ushort)); static assert(is(Unsigned!(immutable byte) == immutable ubyte)); static assert(is(Unsigned!(inout int) == inout uint));
Examples:最大の型、すなわち T.sizeof が最大のものを返す。複数の型が 同じサイズである場合、それらのうち最も左にある引数が 返される。符号なし型は転送されるstatic assert(is(Unsigned!(uint) == uint)); static assert(is(Unsigned!(const uint) == const uint)); static assert(is(Unsigned!(ubyte) == ubyte)); static assert(is(Unsigned!(immutable uint) == immutable uint));
unsigned type符号なし型 - template
Largest
(T...) if (T.length >= 1) - 最大の型、すなわち T.sizeof が最大のものを返す。複数の型が 同じサイズである場合、それらのうち最も左にある引数が 返される。typetypeExamples:Tに対応する符号付き型を返す。Tは数値の整数型でなければならない。 そうでない場合は、コンパイル時にエラーが発生する。
static assert(is(Largest!(uint, ubyte, ushort, real) == real)); static assert(is(Largest!(ulong, double) == ulong)); static assert(is(Largest!(double, ulong) == double)); static assert(is(Largest!(uint, byte, double, short) == double)); static if (is(ucent)) static assert(is(Largest!(uint, ubyte, ucent, ushort) == ucent));
- template
Signed
(T) - Tに対応する符号付き型を返す。Tは数値の整数型でなければならない。 そうでない場合は、コンパイル時にエラーが発生する。than以外はExamples:
alias S1 = Signed!uint; static assert(is(S1 == int)); alias S2 = Signed!(const(uint)); static assert(is(S2 == const(int))); alias S3 = Signed!(immutable(uint)); static assert(is(S3 == immutable(int))); static if (is(ucent)) { alias S4 = Signed!ucent; static assert(is(S4 == cent)); }
- template
mostNegative
(T) if (isNumeric!T || isSomeChar!T || isBoolean!T) - 数値型 T の最も負の値を返す。most negative value最も負の値Examples:most negative value最も負の値
static assert(mostNegative!float == -float.max); static assert(mostNegative!double == -double.max); static assert(mostNegative!real == -real.max); static assert(mostNegative!bool == false);
Examples:スカラー型xml-ph-0000@deepl.internalが 多項式の算術式で昇格するimport std.meta : AliasSeq; static foreach (T; AliasSeq!(bool, byte, short, int, long)) static assert(mostNegative!T == T.min); static foreach (T; AliasSeq!(ubyte, ushort, uint, ulong, char, wchar, dchar)) static assert(mostNegative!T == 0);
- template
Promoted
(T) if (isScalarType!T) - スカラ型T が 多項式の算術式で昇格する型を取得する。to promote昇格させるExamples:
ubyte a = 3, b = 5; static assert(is(typeof(a * b) == Promoted!ubyte)); static assert(is(Promoted!ubyte == int)); static assert(is(Promoted!(shared(bool)) == shared(int))); static assert(is(Promoted!(const(int)) == const(int))); static assert(is(Promoted!double == double));
- enum auto
mangledName
(alias sth); - シンボルまたは型sth のマングル名を返す。generic codeテンプレート引数
mangledName
組み込みの.mangleof プロパティと同じですが、 汎用コードではより便利かもしれません。例えば、 staticMapを呼び出す際のテンプレート引数としてExamples:generic codeテンプレート引数import std.meta : AliasSeq; alias TL = staticMap!(mangledName, int, const int, immutable int); static assert(TL == AliasSeq!("i", "xi", "yi"));
- template
Select
(bool condition, T...) if (T.length == 2) - ブール値condition がtrueの場合はT[0] に、それ以外はT[1] にエイリアスする。xml-ph-0003@deepl.internalxml-ph-0003@deepl.internalExamples:
// 型を選択できる static assert(is(Select!(true, int, long) == int)); static assert(is(Select!(false, int, long) == long)); static struct Foo {} static assert(is(Select!(false, const(int), const(Foo)) == const(Foo))); // 記号を選択できる int a = 1; int b = 2; alias selA = Select!(true, a, b); alias selB = Select!(false, a, b); writeln(selA); // 1 writeln(selB); // 2 // (コンパイル時に)式を選択できる enum val = Select!(false, -4, 9 - 6); static assert(val == 3);
- A
select
(bool cond : true, A, B)(Aa
, lazy Bb
);
Bselect
(bool cond : false, A, B)(lazy Aa
, Bb
); - テンプレートパラメータを介して実行する2つの関数のうちの1つを選択する。Parameters: xml-ph-0000@deepl.internal は、実行する関数を決定する。
cond 実行する関数を決定するbool A a
最初の関数 B b
2番目の関数 Returns:withoutなしa
xml-ph-0000@deepl.internalがxml-ph-0001@deepl.internalであるかどうかを評価せずにb
cond がtrue であるかどうかを評価せずに そうでない場合は、b
評価せずにa
。Examples:real run() { return 0; } int fail() { assert(0); } auto a = select!true(run(), fail()); auto b = select!false(fail(), run()); static assert(is(typeof(a) == real)); static assert(is(typeof(b) == real));
- enum auto
hasUDA
(alias symbol, alias attribute); - シンボルが指定のユーザー定義属性を持つかどうかを判断する。See Also:symbol記号Examples:
enum E; struct S {} @("alpha") int a; static assert(hasUDA!(a, "alpha")); static assert(!hasUDA!(a, S)); static assert(!hasUDA!(a, E)); @(E) int b; static assert(!hasUDA!(b, "alpha")); static assert(!hasUDA!(b, S)); static assert(hasUDA!(b, E)); @E int c; static assert(!hasUDA!(c, "alpha")); static assert(!hasUDA!(c, S)); static assert(hasUDA!(c, E)); @(S, E) int d; static assert(!hasUDA!(d, "alpha")); static assert(hasUDA!(d, S)); static assert(hasUDA!(d, E)); @S int e; static assert(!hasUDA!(e, "alpha")); static assert(hasUDA!(e, S)); static assert(!hasUDA!(e, S())); static assert(!hasUDA!(e, E)); @S() int f; static assert(!hasUDA!(f, "alpha")); static assert(hasUDA!(f, S)); static assert(hasUDA!(f, S())); static assert(!hasUDA!(f, E)); @(S, E, "alpha") int g; static assert(hasUDA!(g, "alpha")); static assert(hasUDA!(g, S)); static assert(hasUDA!(g, E)); @(100) int h; static assert(hasUDA!(h, 100)); struct Named { string name; } @Named("abc") int i; static assert(hasUDA!(i, Named)); static assert(hasUDA!(i, Named("abc"))); static assert(!hasUDA!(i, Named("def"))); struct AttrT(T) { string name; T value; } @AttrT!int("answer", 42) int j; static assert(hasUDA!(j, AttrT)); static assert(hasUDA!(j, AttrT!int)); static assert(!hasUDA!(j, AttrT!string)); @AttrT!string("hello", "world") int k; static assert(hasUDA!(k, AttrT)); static assert(!hasUDA!(k, AttrT!int)); static assert(hasUDA!(k, AttrT!string)); struct FuncAttr(alias f) { alias func = f; } static int fourtyTwo() { return 42; } static size_t getLen(string s) { return s.length; } @FuncAttr!getLen int l; static assert(hasUDA!(l, FuncAttr)); static assert(!hasUDA!(l, FuncAttr!fourtyTwo)); static assert(hasUDA!(l, FuncAttr!getLen)); static assert(!hasUDA!(l, FuncAttr!fourtyTwo())); static assert(!hasUDA!(l, FuncAttr!getLen())); @FuncAttr!getLen() int m; static assert(hasUDA!(m, FuncAttr)); static assert(!hasUDA!(m, FuncAttr!fourtyTwo)); static assert(hasUDA!(m, FuncAttr!getLen)); static assert(!hasUDA!(m, FuncAttr!fourtyTwo())); static assert(hasUDA!(m, FuncAttr!getLen()));
- template
getUDAs
(alias symbol, alias attribute) - 指定されたシンボルから一致するユーザー定義属性を取得する。UDAが型である場合、シンボル上の同じ型のUDAはすべて一致する。 UDAが型のテンプレートである場合、そのテンプレートのインスタンスであるUDAはすべて一致する。 また、UDAが値である場合、 シンボル上のその値と等しいUDAはすべて一致する。See Also:typeシンボルExamples:
struct Attr { string name; int value; } @Attr("Answer", 42) int a; static assert(getUDAs!(a, Attr).length == 1); static assert(getUDAs!(a, Attr)[0].name == "Answer"); static assert(getUDAs!(a, Attr)[0].value == 42); @(Attr("Answer", 42), "string", 9999) int b; static assert(getUDAs!(b, Attr).length == 1); static assert(getUDAs!(b, Attr)[0].name == "Answer"); static assert(getUDAs!(b, Attr)[0].value == 42); @Attr("Answer", 42) @Attr("Pi", 3) int c; static assert(getUDAs!(c, Attr).length == 2); static assert(getUDAs!(c, Attr)[0].name == "Answer"); static assert(getUDAs!(c, Attr)[0].value == 42); static assert(getUDAs!(c, Attr)[1].name == "Pi"); static assert(getUDAs!(c, Attr)[1].value == 3); static assert(getUDAs!(c, Attr("Answer", 42)).length == 1); static assert(getUDAs!(c, Attr("Answer", 42))[0].name == "Answer"); static assert(getUDAs!(c, Attr("Answer", 42))[0].value == 42); static assert(getUDAs!(c, Attr("Answer", 99)).length == 0); struct AttrT(T) { string name; T value; } @AttrT!uint("Answer", 42) @AttrT!int("Pi", 3) @AttrT int d; static assert(getUDAs!(d, AttrT).length == 2); static assert(getUDAs!(d, AttrT)[0].name == "Answer"); static assert(getUDAs!(d, AttrT)[0].value == 42); static assert(getUDAs!(d, AttrT)[1].name == "Pi"); static assert(getUDAs!(d, AttrT)[1].value == 3); static assert(getUDAs!(d, AttrT!uint).length == 1); static assert(getUDAs!(d, AttrT!uint)[0].name == "Answer"); static assert(getUDAs!(d, AttrT!uint)[0].value == 42); static assert(getUDAs!(d, AttrT!int).length == 1); static assert(getUDAs!(d, AttrT!int)[0].name == "Pi"); static assert(getUDAs!(d, AttrT!int)[0].value == 3); struct SimpleAttr {} @SimpleAttr int e; static assert(getUDAs!(e, SimpleAttr).length == 1); static assert(is(getUDAs!(e, SimpleAttr)[0] == SimpleAttr)); @SimpleAttr() int f; static assert(getUDAs!(f, SimpleAttr).length == 1); static assert(is(typeof(getUDAs!(f, SimpleAttr)[0]) == SimpleAttr)); struct FuncAttr(alias f) { alias func = f; } static int add42(int v) { return v + 42; } static string concat(string l, string r) { return l ~ r; } @FuncAttr!add42 int g; static assert(getUDAs!(g, FuncAttr).length == 1); static assert(getUDAs!(g, FuncAttr)[0].func(5) == 47); static assert(getUDAs!(g, FuncAttr!add42).length == 1); static assert(getUDAs!(g, FuncAttr!add42)[0].func(5) == 47); static assert(getUDAs!(g, FuncAttr!add42()).length == 0); static assert(getUDAs!(g, FuncAttr!concat).length == 0); static assert(getUDAs!(g, FuncAttr!concat()).length == 0); @FuncAttr!add42() int h; static assert(getUDAs!(h, FuncAttr).length == 1); static assert(getUDAs!(h, FuncAttr)[0].func(5) == 47); static assert(getUDAs!(h, FuncAttr!add42).length == 1); static assert(getUDAs!(h, FuncAttr!add42)[0].func(5) == 47); static assert(getUDAs!(h, FuncAttr!add42()).length == 1); static assert(getUDAs!(h, FuncAttr!add42())[0].func(5) == 47); static assert(getUDAs!(h, FuncAttr!concat).length == 0); static assert(getUDAs!(h, FuncAttr!concat()).length == 0); @("alpha") @(42) int i; static assert(getUDAs!(i, "alpha").length == 1); static assert(getUDAs!(i, "alpha")[0] == "alpha"); static assert(getUDAs!(i, 42).length == 1); static assert(getUDAs!(i, 42)[0] == 42); static assert(getUDAs!(i, 'c').length == 0);
- template
getSymbolsByUDA
(alias symbol, alias attribute) - Parameters: 検索対象の集約型またはモジュール
symbol 検索対象の集約型またはモジュール attribute 検索するユーザー定義属性 Returns: xml-ph-0000@deepl.internal内の指定のUDAxml-ph-0001@deepl.internalを持つすべてのシンボル。注 これは再帰的ではない。つまり、ネストされた構造体やユニオンなどのシンボル内のシンボルは検索されない。symbol 内のすべてのシンボルで、指定のUDAattribute を持つもの。注釈: これは再帰的ではない。つまり、ネストされた構造体や共用体などのシンボル内のシンボルは検索されない。
Examples:not recursive再帰的ではないenum Attr; struct A { @Attr int a; int b; } static assert(getSymbolsByUDA!(A, Attr).length == 1); static assert(hasUDA!(getSymbolsByUDA!(A, Attr)[0], Attr));
Examples:enum Attr; static struct A { @Attr int a; int b; @Attr void doStuff() {} void doOtherStuff() {} static struct Inner { // getSymbolsByUDAでは見つからない @Attr int c; } } // この属性を持つ変数と関数を見つけるが、 // この属性を持たない変数と関数は含まない。 static assert(getSymbolsByUDA!(A, Attr).length == 2); // getSymbolsByUDAが返すシンボルの属性にアクセスできる。 static assert(hasUDA!(getSymbolsByUDA!(A, Attr)[0], Attr)); static assert(hasUDA!(getSymbolsByUDA!(A, Attr)[1], Attr));
Examples: 複数の属性を検索する複数の属性を検索するstatic struct UDA { string name; } static struct B { @UDA("X") int x; @UDA("Y") int y; @(100) int z; } // 両方のUDA属性を検索する。 static assert(getSymbolsByUDA!(B, UDA).length == 2); // `100`属性を1つ見つける。 static assert(getSymbolsByUDA!(B, 100).length == 1); // 戻り値からUDAの値を取得できる static assert(getUDAs!(getSymbolsByUDA!(B, UDA)[0], UDA)[0].name == "X");
attribute属性Examples: 集合シンボル自体にUDAsがあるかを確認する集合シンボル自体にUDAsがあるかを確認するstatic struct UDA { string name; } @UDA("A") static struct C { @UDA("B") int d; } static assert(getSymbolsByUDA!(C, UDA).length == 2); static assert(getSymbolsByUDA!(C, UDA)[0].stringof == "C"); static assert(getSymbolsByUDA!(C, UDA)[1].stringof == "d");
Examples: 特定のUDAを持つメンバーが存在しない場合は何も見つからない特定のUDAを持つメンバーが存在しない場合は何も見つからないstatic struct UDA { string name; } static struct D { int x; } static assert(getSymbolsByUDA!(D, UDA).length == 0);
UDAUDA - enum bool
allSameType
(Ts...); - Returns:xml-ph-0000@deepl.internalxml-ph-0000@deepl.internaltrue すべての型 が同じである場合。TsExamples:
static assert(allSameType!()); static assert(allSameType!(int)); static assert(allSameType!(int, int)); static assert(allSameType!(int, int, int)); static assert(allSameType!(float, float, float)); static assert(!allSameType!(int, double)); static assert(!allSameType!(int, float, double)); static assert(!allSameType!(int, float, double, real)); static assert(!allSameType!(short, int, float, double, real));
- enum auto
ifTestable
(T, alias pred = (a) => a); - Returns: xml-ph-0000@deepl.internalの型がxml-ph-0001@deepl.internal式でテストできる場合、つまり、xml-ph-0002@deeの場合true T という型が 式でテストできる場合、つまり がコンパイル可能な場合。 if if (pred(T.init)) {}Examples:
class C; struct S1; struct S2 { T opCast(T)() const; } static assert( ifTestable!bool); static assert( ifTestable!int); static assert( ifTestable!(S1*)); static assert( ifTestable!(typeof(null))); static assert( ifTestable!(int[])); static assert( ifTestable!(int[string])); static assert( ifTestable!S2); static assert( ifTestable!C); static assert(!ifTestable!S1);
- enum auto
isType
(alias X); - X が型であるかどうかを検出する。is(X) と同様である。これは、 他のテンプレートと組み合わせて使用する場合に便利である。例えば、 allSatisfy!(
isType
, X)。Returns:xml-ph-0000@deepl.internalxml-ph-0000@deepl.internaltrue X が型である場合、 それ以外の場合falseExamples:struct S { template Test() {} } class C {} interface I {} union U {} static assert(isType!int); static assert(isType!string); static assert(isType!(int[int])); static assert(isType!S); static assert(isType!C); static assert(isType!I); static assert(isType!U); int n; void func(){} static assert(!isType!n); static assert(!isType!func); static assert(!isType!(S.Test)); static assert(!isType!(S.Test!()));
- template
isFunction
(alias X) - シンボルまたは型X が関数であるかどうかを検出する。これは、 シンボルが呼び出し可能であるか、is(X == function) を満たすかどうかを検出するのとは異なり、 シンボルが通常の関数宣言を表しているかどうか、すなわち デリゲートや関数ポインタではないかどうかをReturns: xml-ph-0000@deepl.internal が関数である場合、xml-ph-0001@deepl.internal それ以外の場合true X が関数である場合、 それ以外の場合falseSee Also: 使用する。use使用使用する isFunctionPointerまたは isDelegateそれぞれ それらの型を検出するために使用する。Examples:
static void func(){} static assert(isFunction!func); struct S { void func(){} } static assert(isFunction!(S.func));
- template
isFinal
(alias X) - X が最終メソッドまたはクラスであるかどうかを検出する。Returns: xml-ph-0000@deepl.internal が final であれば true、そうでなければ false を返す。finalfinaltrue X false が final であれば true、そうでなければ false を返す。Examples:xml-ph-0000@deepl.internalの型がコピー可能かどうかを判断する。 型がコピーできない場合、xml-ph-0001@deepl.internalのようなコードは失敗する。
class C { void nf() {} static void sf() {} final void ff() {} } final class FC { } static assert(!isFinal!(C)); static assert( isFinal!(FC)); static assert(!isFinal!(C.nf)); static assert(!isFinal!(C.sf)); static assert( isFinal!(C.ff));
- enum auto
isCopyable
(S); - S 型がコピー可能かどうかを決定する。 型がコピーできない場合、MyStruct x; auto y = x; のようなコードはコンパイルに失敗する。 @disable this(this) を使用することで、構造体のコピーを無効にすることができる。関連項目: __traits(xml-ph-0001@deepl.internalxml-ph-0002@deepl.internal
isCopyable
, S) alsoもParameters:S 確認する型。 Returns: xml-ph-0000@deepl.internal がコピーできるかどうか。xml-ph-0001@deepl.internal それ以外の場合。xml-ph-0000@deepl.internalxml-ph-0001@deepl.internaltrue S がコピーできるかどうか。 それ以外。falseExamples:struct S1 {} // よろしい。コピーできる struct S2 { this(this) {}} // よろしい。コピーできる struct S3 {@disable this(this); } // よくない。コピーが無効になっている。 struct S4 {S3 s;} // よくない。フィールドのコピーが無効になっている。 class C1 {} static assert( isCopyable!S1); static assert( isCopyable!S2); static assert(!isCopyable!S3); static assert(!isCopyable!S4); static assert(isCopyable!C1); static assert(isCopyable!int); static assert(isCopyable!(int[]));
- template
DeducedParameterType
(T) - パラメータ型が T 型である式がテンプレート化された関数の引数として渡された場合、IFTIによって推論されるパラメータ型。ポインタ型およびスライス型以外のすべての型については、
DeducedParameterType
!T T と同じです。ポインタおよびスライス型の場合は、T で、 最外層の修飾子が削除されます。
DEEPL APIにより翻訳、ところどころ修正。
このページの最新版(英語)
このページの原文(英語)
翻訳時のdmdのバージョン: 2.109.1
ドキュメントのdmdのバージョン: 2.109.1
翻訳日付 :
HTML生成日時:
編集者: dokutoku