[stdlib] Land OptionSetType et. al.

This has passed review, or at least satisfied Tony Parker, provided we
do something to hide SetAlgebraDispatchType.  I think I can eliminate it
in an imminent commit.

Swift SVN r28892
This commit is contained in:
Dave Abrahams
2015-05-21 22:55:02 +00:00
parent 570e5acc09
commit ad7f7c6779
11 changed files with 531 additions and 481 deletions

View File

@@ -60,6 +60,29 @@ public protocol _RawOptionSetType : RawRepresentable, Equatable {
init(rawValue: RawValue)
}
/// Returns `true` iff `lhs.rawValue == rhs.rawValue`.
public func == <
T : RawRepresentable where T.RawValue : Equatable
>(lhs: T, rhs: T) -> Bool {
return lhs.rawValue == rhs.rawValue
}
/// Returns `true` iff `lhs.rawValue != rhs.rawValue`.
public func != <
T : RawRepresentable where T.RawValue : Equatable
>(lhs: T, rhs: T) -> Bool {
return lhs.rawValue != rhs.rawValue
}
// This overload is needed for ambiguity resolution against the
// implementation of != for T : Equatable
/// Returns `true` iff `lhs.rawValue != rhs.rawValue`.
public func != <
T : Equatable where T : RawRepresentable, T.RawValue : Equatable
>(lhs: T, rhs: T) -> Bool {
return lhs.rawValue != rhs.rawValue
}
public func == <T : _RawOptionSetType>(a: T, b: T) -> Bool {
return a.rawValue == b.rawValue
}
@@ -77,11 +100,6 @@ public prefix func ~ <T : _RawOptionSetType>(a: T) -> T {
return T(rawValue: ~a.rawValue)
}
/// Protocol for C-like option sets.
public protocol _OptionSetType {
// TODO: implementation, API review
}
/// Protocol for `NS_OPTIONS` imported from Objective-C.
public protocol RawOptionSetType : _RawOptionSetType, BitwiseOperationsType,
NilLiteralConvertible {