[swift-evolution] protocol-oriented integers (take 2)

Dave Abrahams dabrahams at apple.com
Mon Jan 30 13:25:05 CST 2017


on Mon Jan 30 2017, Brent Royal-Gordon <swift-evolution at swift.org> wrote:

>> On Jan 29, 2017, at 10:07 PM, Dave Abrahams <dabrahams at apple.com> wrote:
>> 
>>>>> It might make a great deal of sense to support bitwise operations on
>>>>> this type, 
>>>> 
>>>> I think that's a model of SetAlgebra, then, isn't it?
>>> 
>>> Hmm, arguably. It's a shame that we won't be able to use it with
>>> things like `OptionSet`, though.
>> 
>> Why not?  That conforms to SetAlgebra.
>
> I mean that `OptionSet.RawValue` currently has to conform to
> `BitwiseOperations`, 

Actually it doesn't.  You just have to implement these yourself in that
case:

  extension OptionSet where Self.RawValue : BitwiseOperations {
    convenience init()
    mutating func formUnion(_ other: Self)
    mutating func formIntersection(_ other: Self)
    mutating func formSymmetricDifference(_ other: Self)
  }

> but would now need to conform to `BinaryInteger` (or a sub-protocol).

Does that limit you in some useful way?

-- 
-Dave



More information about the swift-evolution mailing list