[swift-evolution] Bitshift operators

Dave Abrahams dabrahams at apple.com
Thu Jun 16 09:36:54 CDT 2016


on Wed Jun 15 2016, Brent Royal-Gordon <swift-evolution at swift.org> wrote:

> 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. 

A proposal is imminent.
-- 
-Dave



More information about the swift-evolution mailing list