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
trueif the argument is a type.
- proc isParam(e) param¶
Returns
trueif the argument is a param.
- proc isPrimitiveType(type t) param¶
Returns
trueif the typetis a primitive type, as defined by the language specification.
- proc isNumericType(type t) param¶
Returns
trueif the typetis one the following types, of any width:int,uint,real,imag,complex.
- proc isIntegralType(type t) param¶
Returns
trueif the typetis one the following types, of any width:int,uint.
- proc isNothingType(type t) param¶
Returns
trueif the typetis thenothingtype.
- proc isBoolType(type t) param¶
Returns
trueif the typetis abooltype, of any width.
- proc isIntType(type t) param¶
Returns
trueif the typetis aninttype, of any width.
- proc isUintType(type t) param¶
Returns
trueif the typetis auinttype, of any width.
- proc isRealType(type t) param¶
Returns
trueif the typetis arealtype, of any width.
- proc isImagType(type t) param¶
Returns
trueif the typetis animagtype, of any width.
- proc isComplexType(type t) param¶
Returns
trueif the typetis acomplextype, of any width.
- proc isStringType(type t) param¶
Returns
trueif the typetis thestringtype.
- proc isBytesType(type t) param¶
Returns
trueif the typetis thebytestype.
- proc isEnumType(type t) param¶
Returns
trueif the typetis anenumtype.
- proc isClassType(type t) param¶
Return true if
tis a class type. Otherwise return false.
- proc isRecordType(type t) param¶
Return true if
tis a record type. Otherwise return false.
- proc isUnionType(type t) param¶
Return true if
tis a union type. Otherwise return false.
- proc isTupleType(type t) param¶
Returns
trueif its argument is a tuple type.
- proc isRangeType(type t) param¶
Return true if argument
tis a range type, false otherwise
- proc isDomainType(type t) param¶
Return true if
tis a domain type. Otherwise return false.
- proc isArrayType(type t) param¶
Return true if
tis an array type. Otherwise return false.
- proc isDmapType(type t) param¶
Return true if
tis a domain map type. Otherwise return false.
- proc isSyncType(type t) param¶
Returns true if
tis a sync type, false otherwise.
- proc isSingleType(type t) param¶
Returns true if
tis a single type, false otherwise.
- proc isAtomicType(type t) param¶
Returns true if
tis an atomic type, false otherwise.
- proc isVoidType(type t) param¶
Returns
trueif the typetis thevoidtype.
- proc isAbstractEnumType(type t) param¶
Returns
trueif the typetis an abstractenumtype (one in which not all symbols have associated integer values).
- proc isHomogeneousTupleType(type t) param¶
Returns
trueif its argument is a homogeneous tuple type.
- proc isExternUnionType(type t) param¶
Returns
trueif the typetis an extern union type.
- proc isRefIterType(type t) param¶
Returns
trueif the typetis a ref iter type.
- proc isPrimitiveValue(e) param¶
Returns
trueif the argument is a value of primitive type.
- proc isNumericValue(e) param¶
Returns
trueif the argument is a value of one the following types:int,uint,real,imag,complex.
- proc isIntegralValue(e) param¶
Returns
trueif the argument is a value of one the following types:int,uint.
- proc isNothingValue(e) param¶
Returns
trueif the argument is anothingvalue (i.e.,none)
- proc isBoolValue(e) param¶
Returns
trueif the argument is aboolvalue.
- proc isIntValue(e) param¶
Returns
trueif the argument is aintvalue.
- proc isUintValue(e) param¶
Returns
trueif the argument is auintvalue.
- proc isRealValue(e) param¶
Returns
trueif the argument is arealvalue.
- proc isImagValue(e) param¶
Returns
trueif the argument is aimagvalue.
- proc isComplexValue(e) param¶
Returns
trueif the argument is acomplexvalue.
- proc isStringValue(e) param¶
Returns
trueif the argument is astringvalue.
- proc isBytesValue(e) param¶
Returns
trueif the argument is abytesvalue.
- proc isEnumValue(e) param¶
Returns
trueif the argument is aenumvalue.
- proc isClassValue(e) param¶
Returns
trueif the argument is a class value
- proc isRecordValue(e) param¶
Returns
trueif the argument is a record value
- proc isUnionValue(e) param¶
Returns
trueif the argument is a union value
- proc isTupleValue(x) param¶
Returns
trueif the argument is a tuple value
- proc isRangeValue(r) param¶
Return true if argument
ris a range, false otherwise
- proc isDomainValue(e) param¶
Return true if
eis a domain. Otherwise return false.
- proc isArrayValue(e) param¶
Return true if
eis an array. Otherwise return false.
- proc isDmapValue(e) param¶
Return true if
eis a domain map. Otherwise return false.
- proc isSyncValue(x) param¶
Returns
trueif the argument is a sync value
- proc isSingleValue(x) param¶
Returns
trueif the argument is a single value
- proc isAtomicValue(e) param¶
Returns
trueif the argument is an atomic value
- proc isPrimitive(e) param¶
Returns
trueif the argument is a primitive type, as defined by the language specification, or a value of a primitive type.
- proc isNumeric(e) param¶
Returns
trueif 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
trueif the argument is one the following types, of any width:int,uint, or a value of such a type.
- proc isNothing(e) param¶
Returns
trueif the argument isnoneor thenothingtype. as defined by the language specification.
- proc isBool(e) param¶
Returns
trueif the argument is abooltype or value, of any width.
- proc isInt(e) param¶
Returns
trueif the argument is aninttype or value, of any width.
- proc isUint(e) param¶
Returns
trueif the argument is auinttype or value, of any width.
- proc isReal(e) param¶
Returns
trueif the argument is arealtype or value, of any width.
- proc isImag(e) param¶
Returns
trueif the argument is animagtype or value, of any width.
- proc isComplex(e) param¶
Returns
trueif the argument is acomplextype or value, of any width.
- proc isString(e) param¶
Returns
trueif the argument is a string or thestringtype.
- proc isBytes(e) param¶
Returns
trueif the argument is a bytes or thebytestype.
- proc isEnum(e) param¶
Returns
trueif the argument is anenumtype or value, of any width.
- proc isClass(e) param¶
Returns
trueif the argument is a class type or value that is not anexternclass, or when the argument isnil.
- proc isRecord(e) param¶
Returns
trueif the argument is a record type or value.
- proc isUnion(e) param¶
Returns
trueif the argument is a union type or value.
- proc isTuple(e) param¶
Returns
trueif the argument is a tuple type or value.
- proc isRange(e) param¶
Returns
trueif the argument is a range type or value.
- proc isDomain(e) param¶
Returns
trueif the argument is a domain or a domain type.
- proc isArray(e) param¶
Returns
trueif the argument is an array or an array type.
- proc isDmap(e) param¶
Returns
trueif the argument is a domain map or a domain map type.
- proc isSync(e) param¶
Returns
trueif the argument is asynctype or asyncvariable.
- proc isSingle(e) param¶
Returns
trueif the argument is asingletype or asinglevariable.
- proc isAtomic(e) param¶
Returns
trueif the argument is anatomictype or anatomicvariable.
- proc isHomogeneousTuple(e) param¶
Returns
trueif the argument is a homogeneous tuple. The argument must be a tuple or any type.
- proc isGeneric(e) param¶
Returns
trueif the argument is a generic type, andfalseotherwise.
- proc isOwnedClass(e) param¶
Returns
trueif the argument is anownedclass type.
Returns
trueif the argument is asharedclass type.
- proc isUnmanagedClass(e) param¶
Returns
trueif the argument is aunmanagedclass type.
- proc isBorrowedClass(e) param¶
Returns
trueif the argument is aborrowedclass type.
- proc isNilableClass(e) param¶
Returns
trueif the argument is a class type that can storenil.
- proc isNonNilableClass(e) param¶
Returns
trueif the argument is a class type that cannot storenil.
- proc isCopyable(e) param¶
Returns
trueif the argument is a type or an expression of a type that can be copy-initialized andfalseotherwise.Note that even if this function returns
true, it might be the case that the type only supports copy-initialization from mutable values.ownedis an example of a type with that behavior.See also the specification section Copy Initialization of Records.
- proc isConstCopyable(e) param¶
Returns
trueif the argument is a type or an expression of a type that can be copy-initialized from aconstvalue andfalseotherwise.Returns
falseforownedbecause copy-initialization for that type leaves the source argument storingnil.See also the specification section Copy Initialization of Records.
- proc isAssignable(e) param¶
Returns
trueif the argument is a type or expression of a type that can be assigned from another value andfalseotherwise.Note that even if this function returns
true, it might be the case that the type only supports assignment from mutable values.ownedis an example of a type with that behavior.See also the specification section Record Assignment.
- proc isConstAssignable(e) param¶
Returns
trueif the argument is a type or expression of a type that can be assigned from aconstvalue andfalseotherwise.Returns
falseforownedbecause assignment for that type leaves the source argument storingnil.See also the specification section Record Assignment.
- proc isDefaultInitializable(e) param¶
Returns
trueif the argument is a type or expression of a type that can be default initialized andfalseotherwise.Returns
falsefor 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 where t == bool¶
Returns the number of bits used to store the values of type
t. This is available for all numeric types and fixed-widthbooltypes. It is not available for default-widthbool.
- 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-widthbooltypes. It is not available for default-widthbool.
- proc min(type t) param where isBool(t)¶
Returns the minimum value the type
tcan store.tcan be one of the following types, of any width:bool,int,uint,real,imag,complex. Whentis abooltype, it returnsfalse. Whentisreal,imag, orcomplextype, it is a non-paramfunction.
- proc max(type t) param where isBool(t)¶
Returns the maximum value the type
tcan store.tcan be one of the following types, of any width:bool,int,uint,real,imag,complex. Whentis abooltype, it returnstrue. Whentis areal,imag, orcomplextype, it is a non-paramfunction.
- proc integral.safeCast(type T: integral): T¶
Warning
integral.safeCast() is unstable and its behavior may change in the future
The following
safeCast()methods returnthiscast to the typeT. At present, these halt the program ifthiscannot be represented byT, for example(-1).safeCast(uint)or256.safeCast(uint(8)).These methods perform the minimum number of runtime checks. For example, when casting from
uint(8)touint(64), no checks at all will be done.
- proc integral.safeCast(type T: bool)
Warning
integral.safeCast() is unstable and its behavior may change in the future
- proc bool.safeCast(type T: integral)¶
Warning
bool.safeCast() is unstable and its behavior may change in the future
- proc bool.safeCast(type T: bool)
Warning
bool.safeCast() is unstable and its behavior may change in the future
- proc isCoercible(type from, type to) param¶
Returns
trueif the typefromis coercible to the typeto, or ifisSubtype(from, to)would returntrue. See Implicit Conversions for Function Calls.
- proc isSubtype(type sub, type sup) param¶
Returns
trueif the typesubis a subtype of the typesup. See also Implicit Subtype Conversions.In particular, returns
truein any of these cases:subis the same type assupsubis an instantiation of a generic typesupsubis a class type inheriting fromsupsubis non-nilable class type andsupis the nilable version of the same class type
- proc isProperSubtype(type sub, type sup) param¶
Similar to
isSubtypebut returnsfalseifsubandsuprefer to the same type.
- operator <(type a, type b) param¶
Warning
< operator is deprecated when comparing types; use isProperSubtype() instead
- Returns
isProperSubtype(a,b)
- operator <=(type a, type b) param¶
Warning
<= operator is deprecated when comparing types; use isSubtype() instead
- Returns
isSubtype(a,b)
- operator >(type a, type b) param¶
Warning
> operator is deprecated when comparing types; use isProperSubtype() instead
- Returns
isProperSubtype(b,a)
- operator >=(type a, type b) param¶
Warning
>= operator is deprecated when comparing types; use isSubtype() instead
- Returns
isSubtype(b,a)