[swift-dev] Rebinding UnsafePointer makes it mutable

Martin R martinr448 at gmail.com
Mon Sep 19 03:24:04 CDT 2016


I noticed that both UnsafePointer and UnsafeMutablePointer have the identical method

    public func withMemoryRebound<T, Result>(to: T.Type, capacity count: Int, _ body: (UnsafeMutablePointer<T>) throws -> Result) rethrows -> Result

so that rebinding an immutable pointer gives you a _mutable_ pointer. That is different from what

    Unsafe[Mutable]Pointer<Pointee> {
      func withMemoryRebound<T>(to: T.Type, capacity count: Int,
        _ body: (Unsafe[Mutable]Pointer<T>) throws -> ()) rethrows
    }

in https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md indicates. Perhaps I am misunderstanding something. Shouldn't rebinding an UnsafePointer result in an UnsafePointer again?

Martin



More information about the swift-dev mailing list