How can I make a container with copy-on-write semantics? (Swift)
问题 I have a very large structure, which I want to ensure is not copied needlessly. How can I make a copy-on-write container for it? 回答1: A copy-on-write is usually a struct wrapper over some backing object. public final class MutableHeapStore<T>: NonObjectiveCBase { public typealias Storage = T public private(set) var storage: Storage public init(storage: Storage) { self.storage = storage } } public struct COW<T> { public typealias Storage = MutableHeapStore<T> public typealias Value = T public