1.2swift初见的泛型部分的最后一块代码

This commit is contained in:
huangqiaobo
2014-09-05 20:33:59 +08:00
parent 00ef4e6c14
commit b3a016b2a5

View File

@ -707,7 +707,7 @@ possibleInteger = .Some(100)
在类型名后面使用`where`来指定对类型的需求,比如,限定类型实现某一个协议,限定两个类型是相同的,或者限定某个类必须有一个特定的父类 在类型名后面使用`where`来指定对类型的需求,比如,限定类型实现某一个协议,限定两个类型是相同的,或者限定某个类必须有一个特定的父类
```swift ```swift
func anyCommonElements <T, U where T: Sequence, U: Sequence, T.GeneratorType.Element: Equatable, T.GeneratorType.Element == U.GeneratorType.Element> (lhs: T, rhs: U) -> Bool { func anyCommonElements <T, U where T: SequenceType, U: SequenceType, T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element> (lhs: T, rhs: U) -> Bool {
for lhsItem in lhs { for lhsItem in lhs {
for rhsItem in rhs { for rhsItem in rhs {
if lhsItem == rhsItem { if lhsItem == rhsItem {