stdlib: Use config directives to work without objective-c.

Swift SVN r23211
This commit is contained in:
Graham Batty
2014-11-10 20:06:25 +00:00
parent 98586b32e5
commit dc6a776d10
27 changed files with 290 additions and 18 deletions

View File

@@ -286,7 +286,15 @@ public struct ${Self}<T> : MutableCollectionType, Sliceable {
}
public
%if Self == 'Array':
#if _runtime(_ObjC)
typealias _Buffer = _ArrayBuffer<T>
#else
typealias _Buffer = _ContiguousArrayBuffer<T>
#endif
%else:
typealias _Buffer = _${Self.strip('_')}Buffer<T>
%end
/// Initialization from an existing buffer does not have "array.init"
/// semantics because the caller may retain an alias to buffer.
@@ -1139,13 +1147,18 @@ public func !=<T: Equatable>(lhs: ${Self}<T>, rhs: ${Self}<T>) -> Bool {
}
%end
#if _runtime(_ObjC)
/// Returns an Array<Base> containing the same elements as a in
/// O(1). Requires: Base is a base class or base @objc protocol (such
/// as AnyObject) of Derived.
/// FIXME: Dynamic casting is currently not possible without the objc runtime:
/// rdar://problem/18801510
public func _arrayUpCast<Derived, Base>(a: Array<Derived>) -> Array<Base> {
return Array(a._buffer.castToBufferOf(Base.self))
}
#endif
#if _runtime(_ObjC)
extension Array {
/// Try to downcast the source `NSArray` as our native buffer type.
/// If it succeeds, create a new `Array` around it and return that.
@@ -1181,7 +1194,7 @@ extension Array {
self = Array(_ArrayBuffer(selectedSource))
}
}
#endif
// ${'Local Variables'}:
// eval: (read-only-mode 1)