[swift-evolution] Bitshift operators
Ben Rimmington
me at benrimmington.com
Sat Jun 18 15:47:43 CDT 2016
> On 18 Jun 2016, at 02:25, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>
> on Fri Jun 17 2016, Ben Rimmington <swift-evolution at swift.org> wrote:
>
>> <https://swift.org/documentation/api-design-guidelines/#type-conversion>
>>
>>> **In initializers that perform full-width type conversions, omit the
>>> first argument label**, e.g. `Int64(someUInt32)`
>>
>> OptionSet could add `init(_ rawValue: RawValue)` to reduce boilerplate:
>>
>> struct FooOptions: OptionSet {
>> let rawValue: Int
>>
>> static let bar = Self(0b01)
>> static let baz = Self(0b10)
>> }
>
> Great idea; please submit a proposal!
>
> --
> -Dave
On second thoughts, perhaps the current design is better. OptionSet changes the failable initializer (inherited from RawRepresentable) into a *nonfailable* initializer. But if we used `init(_ rawValue: RawValue)` in OptionSet, it would also still have the failable initializer (which could maybe have a default implementation).
The original FooOptions example is missing some required boilerplate: `init(rawValue: Int) { self.rawValue = rawValue }`. In the future, a *macro* could be used to hide the RawRepresentable requirements of option sets, making them as easy to read/write as enum cases.
-- Ben
More information about the swift-evolution
mailing list