Avatar
Swift ↓ちゃんとできてるなぁ。 var a = [2, 3, 5] var b = a a.withUnsafeMutableBufferPointer { $0.baseAddress!.pointee = -1 } print(a) // [-1, 3, 5] print(b) // [2, 3, 5] var a = [2, 3, 5] var b = a a.withUnsafeBufferPointer { UnsafeMutablePointer(mutating: $0.baseAddress!).pointee = -1 } print(a) // [-1, 3, 5] print(b) // [-1, 3, 5]
3:27 AM
一瞬前者でも CoW が働かないんじゃないかと思ってヒヤッとした。 (edited)