i = startIndex, e = endIndex while i != e { yield &self[i] self.formIndex(after: &i) } } for inout employee in company.employees { employee.respected = true } 2 OwnershipManifesto 26
? nil : self[0] } modify { var tmp: Optional<Element> = nil if isEmpty { tmp = nil yield &tmp if let newValue = tmp { self.append(newValue) } } else { // put array into temporarily invalid state tmp = _storage.move() // code to restore valid state put in defer defer { if let newValue = tmp { _storage.initialize(to: newValue) } else { _storage.moveInitialize(from: _storage + 1, count: self.count - 1) self.count -= 1 } } // yield that moved value to the caller yield &tmp } } } 35
Int) -> Element { get { // This call may be hoisted or eliminated by the optimizer. If // there is an inout violation, this value may be stale so needs to be // checked again below. let wasNativeTypeChecked = _hoistableIsNativeTypeChecked() // Make sure the index is in range and wasNativeTypeChecked is // still valid. let token = _checkSubscript( index, wasNativeTypeChecked: wasNativeTypeChecked) return _getElement( index, wasNativeTypeChecked: wasNativeTypeChecked, matchingSubscriptCheck: token) } _modify { _makeMutableAndUnique() // makes the array native, too _checkSubscript_native(index) let address = _buffer.subscriptBaseAddress + index yield &address.pointee } } } 4 stdlib/public/core/Array.swift 44