Span 类型

版本新特性 / Swift 6.2

// *** in version 6.2: ***
//Span is a safe view over a contiguous
//piece of memory: no copying, no pointers
func total(_ span: Span<Int>) -> Int {
    var sum = 0
    for i in span.indices {
        sum += span[i]
    }
    return sum
}

let rgb: [3 of Int] = [255, 128, 0]
print("total is \(total(rgb.span))")
//total is 383