• Slang Standard Library Reference
    • Interfaces
    • Types
      • Buffer types
      • Math types
      • Miscelaneous types
      • Ray-tracing
      • Sampler types
      • Scalar types
      • Stage IO types
      • Texture types
      • Array
      • Atomic
      • AtomicAdd
      • BindlessDescriptorOptions
      • ConstantBuffer
      • CoopMat
      • CoopMatClampMode
      • CoopMatMatrixLayout
      • CoopMatMatrixUse
      • CoopVec
      • CoopVecComponentType
      • CoopVecMatrixLayout
      • DefaultVkBindlessBindings
      • DescriptorAccess
      • DescriptorHandle
      • DescriptorKind
      • DiffTensorView
      • DifferentialPair
      • DifferentialPtrPair
      • DispatchNodeInputRecord
      • MemoryScope
      • NodePayloadPtr
      • NullDifferential
      • Optional
        • hasValue
        • init
        • value
      • ParameterBlock
      • Ptr
      • String
      • TensorLayout
      • TensorView
      • TorchTensor
      • Tuple
      • VkMutableBindlessBindings
      • _AttributeTargets
      • int8_t4_packed
      • uint8_t4_packed
    • Attributes
    • Global Declarations

struct Optional<T>

Description

Optional<T> is a type with one extra value than T, this extra value is used to represent a “missing” or “invalid” T. This extra value is called none.

none can be compared against with the operators == or !=.

An Optional<T> value can also be implicitly or explicitly constructed from a value of type T

Optional<T> values can be deconstructed with if(let myT=myOptionalT)… where this branch will only be taken if myOptionalT contains a value of type T (to be put into scope as myT).

Generic Parameters

T

Properties

hasValue

Return true iff this Optional contains a value of type T

value

If this Optional contains a value of type T return that.

Methods