Skip to content

Instantly share code, notes, and snippets.

@beccadax
Last active July 3, 2016 07:15
Show Gist options
  • Save beccadax/8f4ed4decafc1d18c4441092baa13cfe to your computer and use it in GitHub Desktop.
Save beccadax/8f4ed4decafc1d18c4441092baa13cfe to your computer and use it in GitHub Desktop.
Bikeshedding of SE-0107.
struct UnsafeMutableRawPointer : Strideable, Hashable, _Pointer {
// Anything I don't list, I'm okay with. SE-0107 names are commented
// out above my alternatives.
// I don't like the use of `cast` for these. Yes, "cast" is its own
// past participle, but it's not clear that these operations are
// nonmutating. I prefer `casting` because it's clearer about that.
//
// func cast<T>(to: UnsafeMutablePointer<T>.Type) -> UnsafeMutablePointer<T>
// func cast<T>(to: UnsafePointer<T>.Type) -> UnsafePointer<T>
func casting<T>(to: UnsafeMutablePointer<T>.Type) -> UnsafeMutablePointer<T>
func casting<T>(to: UnsafePointer<T>.Type) -> UnsafePointer<T>
// In general, I think you "initialize to" a value, not
// "initialize with" a value. "with" is needlessly vacuous.
//
// func initialize<T>(_: T.Type, with: T, count: Int = 1)
// -> UnsafeMutablePointer<T>
func initialize<T>(_: T.Type, to: T, count: Int = 1)
-> UnsafeMutablePointer<T>
// In addition to the above point, I don't think "to" belongs in
// front of "contiguous" here. It makes sense with the verbs in
// `load` and `storeRaw` below, but not with this verb.
//
// I also think `contiguous` basically implies `Index`, so we can
// just use `at`. Yes, I know about the `load` method with
// `atByteOffset`.
//
// func initialize<T>(toContiguous: T.Type, atIndex: Int, with: T)
// -> UnsafeMutablePointer<T>
func initialize<T>(contiguous: T.Type, at: Int, to: T)
-> UnsafeMutablePointer<T>
// I'm not happy with the asymmetry of these forwards/backwards
// pairs.
//
// func initialize<T>(from: UnsafePointer<T>, count: Int)
// -> UnsafeMutablePointer<T>
// func initializeBackward<T>(from: UnsafePointer<T>, count: Int)
// -> UnsafeMutablePointer<T>
func initialize<T>(from: UnsafePointer<T>, forwardToCount: Int)
-> UnsafeMutablePointer<T>
func initialize<T>(from: UnsafePointer<T>, backwardFromCount: Int)
-> UnsafeMutablePointer<T>
// More detailed thoughts on redesigining `move` methods in the
// email, but for now:
//
// func moveInitialize<T>(from: UnsafePointer<T>, count: Int)
// -> UnsafeMutablePointer<T>
// func moveInitializeBackward<T>(from: UnsafePointer<T>, count: Int)
// -> UnsafeMutablePointer<T>
func moveInitialize<T>(from: UnsafePointer<T>, forwardToCount: Int)
-> UnsafeMutablePointer<T>
func moveInitialize<T>(from: UnsafePointer<T>, backwardFromCount: Int)
-> UnsafeMutablePointer<T>
// A little backwards, but `as` here is to support a more fluent
// `storeRaw` equivalent.
//
// func load<T>(_: T.Type) -> T
// func load<T>(_: T.Type, atByteOffset: Int) -> T
func load<T>(as: T.Type) -> T
func load<T>(fromByteOffset: Int, as: T.Type) -> T
// func load<T>(fromContiguous: T.Type, atIndex: Int) -> T
func load<T>(fromContiguous: T.Type, at: Int) -> T
// I'm reversing the arguments here because the thing being stored is
// the obvious direct object of the verb "store".
//
// func storeRaw<T>(_: T.Type, with: T)
// func storeRaw<T>(toContiguous: T.Type, at: Int, with: T)
func storeRaw<T>(_: T, as: T.Type)
func storeRaw<T>(_: T, toContiguous: T.Type, at: Int)
// Altering conventions to match above.
//
// func storeRaw<T>(contiguous: T.Type, from: UnsafeRawPointer, count: Int)
// func storeRawBackward<T>(
// contiguous: T.Type, from: UnsafeRawPointer, count: Int)
func storeRaw<T>(contiguous: T.Type, from: UnsafeRawPointer, forwardToCount: Int)
func storeRaw<T>(contiguous: T.Type, from: UnsafeRawPointer, backwardFromCount: Int)
}
extension UnsafeMutablePointer<Pointee> {
// Altering conventions to match above.
//
// func assign(from source: UnsafePointer<Pointee>, count: Int)
// func assignBackward(from source: UnsafePointer<Pointee>, count: Int)
func assign(from source: UnsafePointer<Pointee>, forwardToCount: Int)
func assign(from source: UnsafePointer<Pointee>, backwardFromCount: Int)
// More on these in the email
func move() -> Pointee
func moveAssign(from source: UnsafeMutablePointer<Pointee>, count: Int)
// "Initialize to", not "with".
//
// func initialize(with newValue: Pointee, count: Int = 1)
func initialize(to newValue: Pointee, count: Int = 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment