I don't think same-type constraints are enough here -- in addition to allowing multiple conformances, we'd also need parameterized extensions:
extension Optional: AtomicProtocol where Wrapped == UnsafeRawPointer { ... }
extension Optional: AtomicProtocol where Wrapped == UnsafeMutableRawPointer { ... }
extension<Pointee> Optional: AtomicProtocol
where Wrapped == UnsafePointer<Pointee> {...}
extension<Pointee> Optional: AtomicProtocol
where Wrapped == UnsafeMutablePointer<Pointee> {...}
extension<Instance: AnyObject> Optional: AtomicProtocol
where Wrapped == Unmanaged<Instance>
This would be really, really nice, but I don't see how we could do this yet.
It's one additional protocol. The additional members it requires are indeed piling on top of the heap'o'junk created by AtomicProtocol
, but I don't think that's a big deal. (I'd love to get rid of the ability to call AtomicProtocol's members outside generic contexts...)
(Edit: the reason I don't think it's a big deal is that these extra functions won't pollute type namespaces for people unless they import the Atomics module. Cutting the number of members by half would be nice, but I think the eight AtomicProtocol
requirements already do far more aesthetic damage on their own. Going from 0 to 8 is a far bigger deal than going from 8 to 16. )
This is definitely possible. I was worried the default implementations could potentially trigger for types that happen to be RawRepresentable but need custom atomics, making it more difficult to correctly implement AtomicProtocol
. This is a rather esoteric concern though -- I don't object to removing AtomicRepresentable
.