[swift-evolution] List of all Enum values (for simple enums)

Chris Lattner clattner at apple.com
Wed Dec 9 19:26:32 CST 2015

> On Dec 9, 2015, at 5:24 PM, Jacob Bandes-Storch <jtbandes at gmail.com> wrote:
> On Wed, Dec 9, 2015 at 5:05 PM, Chris Lattner <clattner at apple.com <mailto:clattner at apple.com>> wrote:
>> On Dec 9, 2015, at 10:19 AM, David Waite <david at alkaline-solutions.com <mailto:david at alkaline-solutions.com>> wrote:
>> There are a number of possible proposals for enhancements I see off the bat for “basic" enums (without associated data):
>> 1. A generated implementation of SequenceType based on declaration order
>> 2. A second interface or extension to the enum type could supply static max and min properties when the RawValue is Comparable
>> 3. For enums with a String raw value, CustomStringConvertible and Streamable might make sense as well. You would likely want CustomDebugStringConvertible to also be defined to supply the original type-based value.
> Another design point to consider: instead of making *every* enum generate the “allValues” capability, it might make sense to restrict this synthesization to enums that opt into it by conforming to a protocol.  Intentionally not the right protocol name, but perhaps:
> enum X { A, B }  // not enumerable.
> enum X : Enumerable { A, B } // has allValues and other stuff automatically generated.
> -Chris
> And I suppose it would have to be possible to add this conformance to a pre-existing type?  You'd want to be able to do "extension NSTextAlignment : Enumerable {}”. 

Yes, exactly.  This would allow it to work with C types as you suggest, as well as providing the ability to retroactively provide it for Swift enums that didn’t anticipate the need.

> But I'm not sure if it would work well to generate this on-demand; might work better to do it at interface-generation time, along with OptionSetType conformances, etc.

I’m not sure what you mean here,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151209/3618ae7f/attachment-0001.html>

More information about the swift-evolution mailing list