View source code
							
							
						
								Display the source code in std/traits.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								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.
							
						Module std.traits
Templates which extract information about types and symbols at compile time.
Functions
| Name | Description | 
|---|---|
| 
									lvalueOf()
								 | Creates an lvalue or rvalue of type Tfortypeof(...)and__traits(compiles, ...)purposes. No actual value is returned. | 
| 
									rvalueOf()
								 | Creates an lvalue or rvalue of type Tfortypeof(...)and_traits(compiles, ...)purposes. No actual value is returned. | 
| 
									select(a, b)
								 | Select one of two functions to run via template parameter. | 
Enums
| Name | Description | 
|---|---|
| 
									FunctionAttribute
								 | Returns the FunctionAttribute mask for function func. | 
| 
									ParameterStorageClass
								 | Get tuple, one per function parameter, of the storage classes of the parameters. | 
| 
									Variadic
								 | Determines what kind of variadic parameters function has. | 
Templates
| Name | Description | 
|---|---|
| 
									SetFunctionAttributes
								 | Constructs a new function or delegate type with the same basic signature as the given one, but different attributes (including linkage). | 
Manifest constants
| Name | Type | Description | 
|---|---|---|
| allSameType | ||
| arity | Returns the number of arguments of function func.
arity is undefined for variadic functions. | |
| extractParameterStorageClassFlags | Convert the result of __traits(getParameterStorageClasses)toParameterStorageClassenums. | |
| fullyQualifiedName | Get the fully qualified name of a type or a symbol. Can act as an intelligent type/symbol to string converter. | |
| functionAttributes | Returns the FunctionAttribute mask for function func. | |
| functionLinkage | Determine the linkage attribute of the function. | |
| hasAliasing | Returns trueif and only ifT's representation includes at
least one of the following:
 | |
| hasElaborateAssign | True if Sor any type directly embedded in the representation ofSdefines an elaborate assignment. Elaborate assignments are introduced by
   definingopAssign(typeof(this))oropAssign(ref typeof(this))for astructor when there is a compiler-generatedopAssign. | |
| hasFunctionAttributes | Checks whether a function has the given attributes attached. | |
| hasIndirections | Returns trueif and only ifT's representation includes at
least one of the following:
 | |
| hasMember | Yields trueif and only ifTis an aggregate that defines
   a symbol calledname. | |
| hasNested | Determines whether Tor any of its representation types
have a context pointer. | |
| hasStaticMember | Whether the symbol represented by the string, member, exists and is a static member of T. | |
| hasUDA | Determine if a symbol has a given user-defined attribute. | |
| hasUnsharedAliasing | Returns trueif and only ifT's representation includes at
least one of the following:
 | |
| ifTestable | ||
| isAbstractClass | Detect whether Tis an abstract class. | |
| isAbstractFunction | Detect whether Tis an abstract function. | |
| isAggregateType | Detect whether type Tis an aggregate type. | |
| isArray | Detect whether type Tis an array (static or dynamic; for associative
  arrays seeisAssociativeArray). | |
| isAssignable | Returns trueiff a value of typeRhscan be assigned to a variable of
typeLhs. | |
| isAssociativeArray | Detect whether Tis an associative array type | |
| isAutodecodableString | Detect whether type Tis a string that will be autodecoded. | |
| isBasicType | Detect whether Tis a basic type (scalar type or void). | |
| isBoolean | Detect whether Tis a built-in boolean type. | |
| isBuiltinType | Detect whether type Tis a builtin type. | |
| isCallable | Detect whether Tis a callable object, which can be called with the
function call operatorclass="pln">LPAREN...class="pln">RPAREN. | |
| isConvertibleToString | Warning: This trait will be deprecated as soon as it is no longer used in Phobos. For a function parameter to safely accept a type that implicitly converts to string as a string, the conversion needs to happen at the callsite; otherwise, the conversion is done inside the function, and in many cases, that means that local memory is sliced (e.g. if a static array is passed to the function, then it's copied, and the resulting dynamic array will be a slice of a local variable). So, if the resulting string escapes the function, the string refers to invalid memory, and accessing it would mean accessing invalid memory. As such, the only safe way for a function to accept types that implicitly convert to string is for the implicit conversion to be done at the callsite, and that can only occur if the parameter is explicitly typed as an array, whereas using isConvertibleToString in a template constraint would result in the conversion being done inside the function. As such, isConvertibleToString is inherently unsafe and is going to be deprecated. | |
| isCopyable | Determines whether the type Scan be copied.
 If a type cannot be copied, then code such asMyStruct x; auto y = x;will fail to compile.
 Copying for structs can be disabled by using@disable this(this). | |
| isCovariantWith | Determines whether the function type Fis covariant withG, i.e.,
functions of the typeFcan override ones of the typeG. | |
| isDelegate | Detect whether symbol or type Tis a delegate. | |
| isDynamicArray | Detect whether type Tis a dynamic array. | |
| isEqualityComparable | Detects whether Tis a comparable type. Basic types and structs and
 classes that implement opCmp are ordering comparable. | |
| isExpressions | Check whether the tuple T is an expression tuple. An expression tuple only contains expressions. | |
| isFinal | Detect whether Xis a final method or class. | |
| isFinalClass | Detect whether Tis a final class. | |
| isFinalFunction | Detect whether Tis a final function. | |
| isFloatingPoint | Detect whether Tis a built-in floating point type. | |
| isFunction | Detect whether symbol or type Xis a function. This is different that finding
 if a symbol is callable or satisfyingis(X == function), it finds
 specifically if the symbol represents a normal function declaration, i.e.
 not a delegate or a function pointer. | |
| isFunctionPointer | Detect whether symbol or type Tis a function pointer. | |
| isImplicitlyConvertible | Is Fromimplicitly convertible toTo? | |
| isInnerClass | Determines whether Tis a class nested inside another class
and thatTis the implicit reference to the outer class
(i.e.outerhas not been used as a field or method name) | |
| isInstanceOf | Returns true if T is an instance of the template S. | |
| isIntegral | Detect whether Tis a built-in integral type. Typesbool,char,wchar, anddcharare not considered integral. | |
| isIterable | Returns trueif T can be iterated over using aforeachloop with
 a single loop variable of automatically inferred type, regardless of how
 theforeachloop is implemented.  This includes ranges, structs/classes
 that defineopApplywith a single loop variable, and builtin dynamic,
 static and associative arrays. | |
| isMutable | Returns true if T is not const or immutable. Note that isMutable is true for string, or immutable(char)[], because the 'head' is mutable. | |
| isNarrowString | Detect whether type Tis a narrow string. | |
| isNested | Determines whether Thas its own context pointer.Tmust be eitherclass,struct, orunion. | |
| isNestedFunction | Determines if fis a function that requires a context pointer. | |
| isNumeric | Detect whether Tis a built-in numeric type (integral or floating
 point). | |
| isOrderingComparable | Detects whether Tis a comparable type. Basic types and structs and
 classes that implement opCmp are ordering comparable. | |
| isPointer | Detect whether type Tis a pointer. | |
| isSafe | trueiffuncis@safeor@trusted. | |
| isScalarType | Detect whether Tis a scalar type (a built-in numeric, character or
 boolean type). | |
| isSigned | Detect whether Tis a built-in signed numeric type. | |
| isSIMDVector | Detect whether type Tis a SIMD vector type. | |
| isSomeChar | Detect whether Tis one of the built-in character types. | |
| isSomeFunction | Detect whether symbol or type Tis a function, a function pointer or a delegate. | |
| isSomeString | Detect whether Tis one of the built-in string types. | |
| isStaticArray | Detect whether type Tis a static array. | |
| isType | Detect whether Xis a type. Analogous tois(X). This is useful when used
 in conjunction with other templates, e.g.allSatisfy!(isType, X). | |
| isTypeTuple | Check whether the tuple Tis a type tuple.
 A type tuple only contains types. | |
| isUnsafe | trueiffuncis@system. | |
| isUnsigned | Detect whether Tis a built-in unsigned numeric type. | |
| mangledName | Returns the mangled name of symbol or type sth. | |
| moduleName | Get the module name (including package) for the given symbol. | |
| mostNegative | Returns the most negative value of the numeric type T. | |
| packageName | Get the full package name for the given symbol. | |
| variadicFunctionStyle | Determines what kind of variadic parameters function has. | 
Aliases
| Name | Type | Description | 
|---|---|---|
| BaseClassesTuple | AliasSeq!() | Get a AliasSeq of all base classes of this class, in decreasing order. Interfaces are not included. BaseClassesTuple!Object yields the empty type tuple. | 
| BaseTypeTuple | P | Get a AliasSeq of the base class and base interfaces of this class or interface. BaseTypeTuple!Object returns the empty type tuple. | 
| CentTypeList | AliasSeq!(cent,ucent) | |
| classInstanceAlignment | maxAlignment!(void*,typeof(T.tupleof)) | Returns class instance alignment. | 
| CommonType | void | Get the type that all types can be implicitly converted to. Useful e.g. in figuring out an array type from a bunch of initializing values. Returns void if passed an empty list, or if the types have no common type. | 
| ConstOf | const(T) | |
| CopyConstness | Unshared!(CopyTypeQualifiers!(FromType,ToType)) | Returns the type of Targetwith the "constness" ofSource. A type's constness
refers to whether it isconst,immutable, orinout. Ifsourcehas no constness, the
returned type will be the same asTarget. | 
| CopyTypeQualifiers | ModifyTypePreservingTQ!(T,FromType) | Copies type qualifiers from FromTypetoToType. | 
| EnumMembers | EnumSpecificMembers!(__traits(allMembers,E)) | Retrieves the members of an enumerated type enum E. | 
| FieldNameTuple | staticMap!(NameOf,T.tupleof[0..__dollar-isNested!T]) | Get as an expression tuple the names of the fields of a struct, class, or
 union. This consists of the fields that take up memory space, excluding the
 hidden fields like the virtual function table pointer or a context pointer
 for nested types.
 Inherited fields (for classes) are not included.
 If Tisn't a struct, class, or union, an
 expression tuple with an empty string is returned. | 
| Fields | typeof(T | Get as a tuple the types of the fields of a struct, class, or union.
 This consists of the fields that take up memory space,
 excluding the hidden fields like the virtual function
 table pointer or a context pointer for nested types.
 If Tisn't a struct, class, or union returns a tuple
 with one elementT. | 
| FieldTypeTuple |  | Alternate name for Fields, kept for legacy compatibility. | 
| ForeachType | ReturnType!(typeof((inoutintx=0){foreach(elem;T.init){returnelem;}assert(0);})) | Returns the inferred type of the loop variable when a variable of type T
is iterated over using a foreachloop with a single loop variable and
automatically inferred return type.  Note that this may not be the same asstdin the case of narrow strings, or if T
has both opApply and a range interface. | 
| FunctionTypeOf | Fsym | Get the function type from a callable object func. | 
| getSymbolsByUDA | AliasSeq!(symbol,membersWithUDA) | |
| getUDAs | Filter!(isDesiredUDA!attribute,__traits(getAttributes,symbol)) | Gets the matching user-defined attributes from the given symbol. | 
| hasElaborateCopyConstructor | hasElabCCtor!S | True if Sor any type embedded directly in the representation ofSdefines an elaborate copy constructor. Elaborate copy constructors are
 introduced by definingthis(this)for astruct. | 
| hasElaborateDestructor | hasElabDest!S | True if Sor any type directly embedded in the representation
   ofSdefines an elaborate destructor. Elaborate destructors
   are introduced by defining~this()for a   struct. | 
| ImmutableOf | immutable(T) | |
| ImplicitConversionTargets | AliasSeq!(byte,ubyte,short,ushort,int,uint,long,ulong,CentTypeList,float,double,real,char,wchar,dchar) | |
| InoutOf | inout(T) | |
| InterfacesTuple | NoDuplicates!(Flatten!S) | |
| isExpressionTuple |  | Alternate name for isExpressions, kept for legacy compatibility. | 
| KeyType | K | Get the Key type of an Associative Array. | 
| Largest | T[0] | Returns the largest type, i.e. T such that T.sizeof is the largest. If more than one type is of the same size, the leftmost argument of these in will be returned. | 
| MemberFunctionsTuple | shrink!overloads | Returns a tuple of non-static functions with the name namedeclared in the
class or interfaceC.  Covariant duplicates are shrunk into the most
derived one. | 
| OriginalType | ModifyTypePreservingTQ!(Impl,T) | Strips off all enums from typeT. | 
| ParameterDefaults | Impl!() | Get, as a tuple, the default value of the parameters to a function symbol.
If a parameter doesn't have the default value, voidis returned instead. | 
| ParameterDefaultValueTuple |  | Alternate name for ParameterDefaults, kept for legacy compatibility. | 
| ParameterIdentifierTuple | Impl!() | Get, as a tuple, the identifiers of the parameters to a function symbol. | 
| Parameters | P | Get, as a tuple, the types of the parameters to a function, a pointer
to function, a delegate, a struct with an opCall, a pointer to a
struct with anopCall, or a class with anopCall. | 
| ParameterStorageClassTuple | StorageClass!0 | Get tuple, one per function parameter, of the storage classes of the parameters. | 
| ParameterTypeTuple |  | Alternate name for Parameters, kept for legacy compatibility. | 
| PointerTarget | T | Returns the target type of a pointer. | 
| Promoted | CopyTypeQualifiers!(T,typeof(T.init+T.init)) | Get the type that a scalar type Twill promote
to in multi-term arithmetic expressions. | 
| QualifierOf | SharedConstOf | Gives a template that can be used to apply the same
 attributes that are on the given type T. E.g. passinginout shared intwill returnSharedInoutOf. | 
| RepresentationTypeTuple | staticMapMeta!(RepresentationTypeTupleImpl,FieldTypeTuple!T) | Get the primitive types of the fields of a struct or class, in topological order. | 
| ReturnType | CRC | Get the type of the return value from a function,
 a pointer to function, a delegate, a struct
 with an opCall, a pointer to a struct with an opCall,
 or a class with an opCall. Please note that ref
 is not part of a type, but the attribute of the function
 (see templatefunctionAttributes). | 
| Select | Alias!(T[!condition]) | Aliases itself to T[0]if the booleanconditionistrueand toT[1]otherwise. | 
| SetFunctionAttributes | FunctionTypeOf!(SetFunctionAttributes!(T*,linkage,attrs)) | Constructs a new function or delegate type with the same basic signature as the given one, but different attributes (including linkage). | 
| SharedConstOf | const(shared(T)) | |
| SharedInoutOf | inout(shared(T)) | |
| SharedOf | shared(T) | |
| Signed | ModifyTypePreservingTQ!(Impl,OriginalType!T) | Returns the corresponding signed type for T. T must be a numeric integral type, otherwise a compile-time error occurs. | 
| SignedCentTypeList | AliasSeq!cent | |
| TemplateArgsOf | Args | Returns a AliasSeqof the template arguments used to instantiateT. | 
| TemplateOf | Base | Returns an alias to the template that Tis an instance of.
It will returnvoidif a symbol without a template is given. | 
| TransitiveBaseTypeTuple | AliasSeq!() | Get a AliasSeq of all base classes of T, in decreasing order, followed by T's interfaces. TransitiveBaseTypeTuple!Object yields the empty type tuple. | 
| Unqual | CoreUnqual!T | Removes all qualifiers, if any, from type T. | 
| Unsigned | ModifyTypePreservingTQ!(Impl,OriginalType!T) | |
| UnsignedCentTypeList | AliasSeq!ucent | |
| ValueType | V | Get the Value type of an Associative Array. | 
Authors
Walter Bright,
            Tomasz Stachowiak (isExpressions),
            Andrei Alexandrescu,
            Shin Fujishiro,
            Robert Clipsham,
            David Nadlinger,
            Kenji Hara,
            Shoichi Kato
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.