[swift-evolution] [Pitch] UnsafePointer.advanced(to:)

Brent Royal-Gordon brent at architechies.com
Tue Jun 6 10:27:52 CDT 2017

It won't happen for Swift 4, but I think we should eventually have APIs like:

extension UnsafePointer {
    func advanced<T>(to keyPath: KeyPath<Pointee, T>) -> UnsafePointer<T>?

If keyPath referred to a stored property directly inside the value, this would return a pointer to that property. If keyPath is a computed property, or the property is not stored relative to the pointer (e.g. an object or indirect pointer), it returns nil. 

My most immediate use case is for working with MIDI structures, which have an inline byte buffer, but I suspect there will be other uses as well. 

Brent Royal-Gordon
Sent from my iPhone

More information about the swift-evolution mailing list