Re. OptionSetType

If you wrote:

    enum Ex { case one, two, three }

The compiler could do:


   - struct Ex : OptionSetType
   <http://swiftdoc.org/v2.2/protocol/OptionSetType> {
   -   private let weight: Int <http://swiftdoc.org/v2.2/type/Int>
   -   private init(_ weight: Int <http://swiftdoc.org/v2.2/type/Int>) {
   self.weight = weight }
   -
   -   static let one = Ex(1)
   -   static let two = Ex(2)
   -   static let three = Ex(4)
   -   static let values: Ex = [one, two, three]
   - }


Plus the compiler would have to allow statics to have their type inferred,
i.e. you write .one and the compiler infers Ex.one.

This would allow set behaviour which I found very handy in Java.

PS Int only applicable for < 64 cases. Need BigInt for others.

On Saturday, 16 April 2016, Brent Royal-Gordon <[email protected]>
wrote:

> > I would suggest that ValuesEnumerable should expose allValues and the
> type of allValues should be a custom OptionSet implementation that iterates
> in declaration order.
>
> That would make sense if OptionSet were a generic type which took any
> integer-ish RawRepresentable (which I've advocated before, although I sort
> of understand why we haven't gone that route), but it isn't, so I don't
> think that makes a lot of sense for Swift.
>
> --
> Brent Royal-Gordon
> Architechies
>
>

-- 
-- Howard.
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to