Types

Note

All Chapel programs automatically use this module by default. An explicit use statement is not necessary.

Functions related to predefined types.

proc isType(e) param

Returns true if the argument is a type.

proc isParam(e) param

Returns true if the argument is a param.

proc isPrimitiveType(type t) param

Returns true if the type t is a primitive type, as defined by the language specification.

proc isNumericType(type t) param

Returns true if the type t is one the following types, of any width: int, uint, real, imag, complex.

proc isIntegralType(type t) param

Returns true if the type t is one the following types, of any width: int, uint.

proc isFloatType(type t) param

Returns true if the type t is one the following types, of any width: real, imag.

proc isNothingType(type t) param

Returns true if the type t is the nothing type.

proc isVoidType(type t) param

Returns true if the type t is the void type.

proc isBoolType(type t) param

Returns true if the type t is a bool type, of any width.

proc isIntType(type t) param

Returns true if the type t is an int type, of any width.

proc isUintType(type t) param

Returns true if the type t is a uint type, of any width.

proc isEnumType(type t) param

Returns true if the type t is an enum type.

proc isAbstractEnumType(type t) param

Returns true if the type t is an abstract enum type (one in which not all symbols have associated integer values).

proc isComplexType(type t) param

Returns true if the type t is a complex type, of any width.

proc isRealType(type t) param

Returns true if the type t is a real type, of any width.

proc isImagType(type t) param

Returns true if the type t is an imag type, of any width.

proc isStringType(type t) param

Returns true if the type t is the string type.

proc isBytesType(type t) param

Returns true if the type t is the bytes type.

proc isBoolValue(e) param

Returns true if the argument is a bool value.

proc isIntValue(e) param

Returns true if the argument is a int value.

proc isUintValue(e) param

Returns true if the argument is a uint value.

proc isRealValue(e) param

Returns true if the argument is a real value.

proc isImagValue(e) param

Returns true if the argument is a imag value.

proc isComplexValue(e) param

Returns true if the argument is a complex value.

proc isStringValue(e) param

Returns true if the argument is a string value.

proc isBytesValue(e) param

Returns true if the argument is a bytes value.

proc isIntegralValue(e) param

Returns true if the argument is a value of one the following types: int, uint.

proc isFloatValue(e) param

Returns true if the argument is a value of one the following types: real, imag.

proc isNumericValue(e) param

Returns true if the argument is a value of one the following types: int, uint, real, imag, complex.

proc isPrimitiveValue(e) param

Returns true if the argument is a value of primitive type.

proc isEnumValue(e) param

Returns true if the argument is a enum value.

proc isNothingValue(e) param

Returns true if the argument is a nothing value (i.e., none)

proc isNothing(type t) param

Returns true if the argument is none or the nothing type. as defined by the language specification.

proc isNothing(e) param
proc isPrimitive(e) param

Returns true if the argument is a primitive type, as defined by the language specification, or a value of a primitive type.

proc isNumeric(e) param

Returns true if the argument is one the following types, of any width: int, uint, real, imag, complex, or a value of such a type.

proc isIntegral(e) param

Returns true if the argument is one the following types, of any width: int, uint, or a value of such a type.

proc isFloat(e) param

Returns true if the argument is one the following types, of any width: real, imag, or a value of such a type.

proc isBool(e) param

Returns true if the argument is a bool type or value, of any width.

proc isInt(e) param

Returns true if the argument is an int type or value, of any width.

proc isUint(e) param

Returns true if the argument is a uint type or value, of any width.

proc isReal(e) param

Returns true if the argument is a real type or value, of any width.

proc isImag(e) param

Returns true if the argument is an imag type or value, of any width.

proc isComplex(e) param

Returns true if the argument is a complex type or value, of any width.

proc isBytes(e) param

Returns true if the argument is a bytes or the bytes type.

proc isString(e) param

Returns true if the argument is a string or the string type.

proc isEnum(e) param

Returns true if the argument is an enum type or value, of any width.

proc isTuple(e) param

Returns true if the argument is a tuple type or value.

proc isHomogeneousTuple(e: _tuple) param

Returns true if the argument is a homogeneous tuple. The argument must be a tuple or any type.

proc isClass(e) param

Returns true if the argument is a class type or value that is not an extern class, or when the argument is nil.

proc isGeneric(e) param

Returns true if the argument is a generic type, and false otherwise.

proc isOwnedClass(e) param

Returns true if the argument is an owned class type.

proc isSharedClass(e) param

Returns true if the argument is a shared class type.

proc isUnmanagedClass(e) param

Returns true if the argument is a unmanaged class type.

proc isBorrowedClass(e) param

Returns true if the argument is a borrowed class type.

proc isNilableClass(e) param

Returns true if the argument is a class type that can store nil.

proc isNonNilableClass(e) param

Returns true if the argument is a class type that cannot store nil.

proc isRecord(e) param

Returns true if the argument is a record type or value.

proc isUnion(e) param

Returns true if the argument is a union type or value.

proc isRange(e) param

Returns true if the argument is a range type or value.

proc isDmap(e) param

Returns true if the argument is a domain map or a domain map type.

proc isDomain(e) param

Returns true if the argument is a domain or a domain type.

proc isArray(e) param

Returns true if the argument is an array or an array type.

proc isSync(e) param

Returns true if the argument is a sync type or a sync variable.

proc isSingle(e) param

Returns true if the argument is a single type or a single variable.

proc isAtomic(e) param

Returns true if the argument is an atomic type or an atomic variable.

proc isCopyable(e) param

Returns true if the argument is a type or an expression of a type that can be copy-initialized and false otherwise.

Note that even if this function returns true, it might be the case that the type only supports copy-initialization from mutable values. owned is an example of a type with that behavior.

See also the specification section Copy Initialization of Records.

proc isConstCopyable(e) param

Returns true if the argument is a type or an expression of a type that can be copy-initialized from a const value and false otherwise.

Returns false for owned because copy-initialization for that type leaves the source argument storing nil.

See also the specification section Copy Initialization of Records.

proc isAssignable(e) param

Returns true if the argument is a type or expression of a type that can be assigned from another value and false otherwise.

Note that even if this function returns true, it might be the case that the type only supports assignment from mutable values. owned is an example of a type with that behavior.

See also the specification section Record Assignment.

proc isConstAssignable(e) param

Returns true if the argument is a type or expression of a type that can be assigned from a const value and false otherwise.

Returns false for owned because assignment for that type leaves the source argument storing nil.

See also the specification section Record Assignment.

proc isDefaultInitializable(e) param

Returns true if the argument is a type or expression of a type that can be default initialized and false otherwise.

Returns false for non-nilable class types because these types do not have a default value.

See also the specification section Default Initialization.

proc toNilableIfClassType(type arg) type

If the argument is a class type, returns its nilable version like arg?. Otherwise returns the argument unchanged.

proc numBits(type t) param

Returns the number of bits used to store the values of type t. This is available for all numeric types and fixed-width bool types. It is not available for default-width bool.

proc numBytes(type t) param

Returns the number of bytes used to store the values of type t. This is available for all numeric types and fixed-width bool types. It is not available for default-width bool.

proc min(type t) param

Returns the minimum value the type t can store. t can be one of the following types, of any width: bool, int, uint, real, imag, complex. When t is a bool type, it returns false. When t is real, imag, or complex type, it is a non-param function.

proc max(type t) param

Returns the maximum value the type t can store. t can be one of the following types, of any width: bool, int, uint, real, imag, complex. When t is a bool type, it returns true. When t is a real, imag, or complex type, it is a non-param function.

proc integral.safeCast(type T: integral): T

Returns this, cast to the type T. Generates a run-time error if this cannot be represented by T, for example (-1).safeCast(uint) or 256.safeCast(uint(8)).

This method performs the minimum number of runtime checks. For example, when casting from uint(8) to uint(64), no checks at all will be done.

proc isCoercible(type from, type to) param

Returns true if the type from is coercible to the type to, or if isSubtype(from, to) would return true.

proc isSubtype(type sub, type super) param

Returns true if the type sub is a subtype of the type super. In particular, returns true in any of these cases:

  • sub is the same type as super

  • sub is an instantiation of a generic type super

  • sub is a class type inheriting from super

Note that isSubtype(a,b) can also be written as a <= b or b >= a.

proc isProperSubtype(type sub, type super) param

Similar to isSubtype but returns false if sub and super refer to the same type.

Note that isProperSubtype(a,b) can also be written as a < b or b > a.

proc <(type a, type b) param
Returns

isProperSubtype(a,b)

proc <=(type a, type b) param
Returns

isSubtype(a,b)

proc >(type a, type b) param
Returns

isProperSubtype(b,a)

proc >=(type a, type b) param
Returns

isSubtype(b,a)