[swift-evolution] Bitshift operators

Brent Royal-Gordon brent at brentdax.com
Wed Jun 15 02:36:49 CDT 2016


While I was watching WWDC videos today, I noticed that there's a bit of annoying boilerplate in OptionSet specifications, and set out to get rid of it. Basically, what I'd like to do is this:

	extension OptionSet where RawValue: Integer {
	    init(bit bits: RawValue...) {
	        self.init(rawValue: bits.reduce(0) { $0 | (1 << $1) })
	    }
	}

	struct FooOptions: OptionSet {
	    let rawValue: Int
	    
	    static let bar = FooOptions(bit: 0)
	    static let baz = FooOptions(bit: 1)
	}

However, this was thwarted by the fact that the << operator is not in Integer. Or BitwiseOperations. Or any protocol, in fact.

From what I understand, this is a long-known issue we were planning to address in the Integer redesign, but I'm not sure what the status of that is at this point. I would guess that we're facing one of three situations:

1. An Integer redesign is still planned for Swift 3, but hasn't been reviewed yet.
2. An Integer redesign has been deferred, but an incremental improvement (like adding bitshifting to BitwiseOperations) would be welcome.
3. An Integer redesign has been deferred, and an incremental improvement is either not desired or too late at this point.

Can anyone share the status of this? If we're in #2, I'd be happy to put together a quick proposal to patch this particular issue up in time for Swift 3. (I assume that `OptionSet.init(bit:)` would be considered a "new feature" and thus out of scope.)

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list