[swift-users] Why does the withUnsafeMutableBufferPointer closure take an inout parameter?

Guillaume Lessard glessard at tffenterprises.com
Wed Oct 11 15:11:30 CDT 2017


> On Oct 10, 2017, at 01:50, Martin R via swift-users <swift-users at swift.org> wrote:
> 
> Thank you Howard for you response! However, I have a follow-up question:
> 
> Why are UnsafeMutableBufferPointer methods which modify not the buffer pointer itself, but only the pointed-to memory, mutating at all?

Don’t forget that UnsafeMutableBufferPointer conforms to MutableCollection, and that many MutableCollection methods (such as swapAt) must be mutating. The BufferPointer types are unusual among Collection conformers in not having value semantics.

Cheers,
Guillaume Lessard



More information about the swift-users mailing list