1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// This file contains only support for types deprecated from previous versions
// of Swift
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "BidirectionalCollection")
public typealias BidirectionalIndexable = BidirectionalCollection
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "Collection")
public typealias IndexableBase = Collection
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "Collection")
public typealias Indexable = Collection
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "MutableCollection")
public typealias MutableIndexable = MutableCollection
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "RandomAccessCollection")
public typealias RandomAccessIndexable = RandomAccessCollection
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "RangeReplaceableIndexable")
public typealias RangeReplaceableIndexable = RangeReplaceableCollection
@available(swift, deprecated: 4.2, renamed: "EnumeratedSequence.Iterator")
public typealias EnumeratedIterator<T: Sequence> = EnumeratedSequence<T>.Iterator
@available(swift,deprecated: 4.2, obsoleted: 5.0, renamed: "CollectionOfOne.Iterator")
public typealias IteratorOverOne<T> = CollectionOfOne<T>.Iterator
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "EmptyCollection.Iterator")
public typealias EmptyIterator<T> = EmptyCollection<T>.Iterator
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyFilterSequence.Iterator")
public typealias LazyFilterIterator<T: Sequence> = LazyFilterSequence<T>.Iterator
@available(swift, deprecated: 3.1, obsoleted: 5.0, message: "Use Base.Index")
public typealias LazyFilterIndex<Base: Collection> = Base.Index
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyDropWhileSequence.Iterator")
public typealias LazyDropWhileIterator<T> = LazyDropWhileSequence<T>.Iterator where T: Sequence
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyDropWhileCollection.Index")
public typealias LazyDropWhileIndex<T> = LazyDropWhileCollection<T>.Index where T: Collection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyDropWhileCollection")
public typealias LazyDropWhileBidirectionalCollection<T> = LazyDropWhileCollection<T> where T: BidirectionalCollection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyFilterCollection")
public typealias LazyFilterBidirectionalCollection<T> = LazyFilterCollection<T> where T: BidirectionalCollection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyMapSequence.Iterator")
public typealias LazyMapIterator<T, E> = LazyMapSequence<T, E>.Iterator where T: Sequence
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyMapCollection")
public typealias LazyMapBidirectionalCollection<T, E> = LazyMapCollection<T, E> where T: BidirectionalCollection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyMapCollection")
public typealias LazyMapRandomAccessCollection<T, E> = LazyMapCollection<T, E> where T: RandomAccessCollection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyCollection")
public typealias LazyBidirectionalCollection<T> = LazyCollection<T> where T: BidirectionalCollection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyCollection")
public typealias LazyRandomAccessCollection<T> = LazyCollection<T> where T: RandomAccessCollection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "FlattenCollection.Index")
public typealias FlattenCollectionIndex<T> = FlattenCollection<T>.Index where T: Collection, T.Element: Collection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "FlattenCollection.Index")
public typealias FlattenBidirectionalCollectionIndex<T> = FlattenCollection<T>.Index where T: BidirectionalCollection, T.Element: BidirectionalCollection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "FlattenCollection")
public typealias FlattenBidirectionalCollection<T> = FlattenCollection<T> where T: BidirectionalCollection, T.Element: BidirectionalCollection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "JoinedSequence.Iterator")
public typealias JoinedIterator<T: Sequence> = JoinedSequence<T>.Iterator where T.Element: Sequence
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "Zip2Sequence.Iterator")
public typealias Zip2Iterator<T, U> = Zip2Sequence<T, U>.Iterator where T: Sequence, U: Sequence
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyPrefixWhileSequence.Iterator")
public typealias LazyPrefixWhileIterator<T> = LazyPrefixWhileSequence<T>.Iterator where T: Sequence
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyPrefixWhileCollection.Index")
public typealias LazyPrefixWhileIndex<T> = LazyPrefixWhileCollection<T>.Index where T: Collection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "LazyPrefixWhileCollection")
public typealias LazyPrefixWhileBidirectionalCollection<T> = LazyPrefixWhileCollection<T> where T: BidirectionalCollection
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "ReversedCollection")
public typealias ReversedRandomAccessCollection<T: RandomAccessCollection> = ReversedCollection<T>
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "ReversedCollection.Index")
public typealias ReversedIndex<T: BidirectionalCollection> = ReversedCollection<T>.Index
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias BidirectionalSlice<T> = Slice<T> where T: BidirectionalCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias RandomAccessSlice<T> = Slice<T> where T: RandomAccessCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias RangeReplaceableSlice<T> = Slice<T> where T: RangeReplaceableCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias RangeReplaceableBidirectionalSlice<T> = Slice<T> where T: RangeReplaceableCollection & BidirectionalCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias RangeReplaceableRandomAccessSlice<T> = Slice<T> where T: RangeReplaceableCollection & RandomAccessCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias MutableSlice<T> = Slice<T> where T: MutableCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias MutableBidirectionalSlice<T> = Slice<T> where T: MutableCollection & BidirectionalCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias MutableRandomAccessSlice<T> = Slice<T> where T: MutableCollection & RandomAccessCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias MutableRangeReplaceableSlice<T> = Slice<T> where T: MutableCollection & RangeReplaceableCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias MutableRangeReplaceableBidirectionalSlice<T> = Slice<T> where T: MutableCollection & RangeReplaceableCollection & BidirectionalCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "Slice")
public typealias MutableRangeReplaceableRandomAccessSlice<T> = Slice<T> where T: MutableCollection & RangeReplaceableCollection & RandomAccessCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "DefaultIndices")
public typealias DefaultBidirectionalIndices<T> = DefaultIndices<T> where T: BidirectionalCollection
@available(swift, deprecated: 4.0, obsoleted: 5.0, renamed: "DefaultIndices")
public typealias DefaultRandomAccessIndices<T> = DefaultIndices<T> where T: RandomAccessCollection
// Deprecated by SE-0115.
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByNilLiteral")
public typealias NilLiteralConvertible = ExpressibleByNilLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "_ExpressibleByBuiltinIntegerLiteral")
public typealias _BuiltinIntegerLiteralConvertible = _ExpressibleByBuiltinIntegerLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByIntegerLiteral")
public typealias IntegerLiteralConvertible = ExpressibleByIntegerLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "_ExpressibleByBuiltinFloatLiteral")
public typealias _BuiltinFloatLiteralConvertible = _ExpressibleByBuiltinFloatLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByFloatLiteral")
public typealias FloatLiteralConvertible = ExpressibleByFloatLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "_ExpressibleByBuiltinBooleanLiteral")
public typealias _BuiltinBooleanLiteralConvertible = _ExpressibleByBuiltinBooleanLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByBooleanLiteral")
public typealias BooleanLiteralConvertible = ExpressibleByBooleanLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "_ExpressibleByBuiltinUnicodeScalarLiteral")
public typealias _BuiltinUnicodeScalarLiteralConvertible = _ExpressibleByBuiltinUnicodeScalarLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByUnicodeScalarLiteral")
public typealias UnicodeScalarLiteralConvertible = ExpressibleByUnicodeScalarLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "_ExpressibleByBuiltinExtendedGraphemeClusterLiteral")
public typealias _BuiltinExtendedGraphemeClusterLiteralConvertible = _ExpressibleByBuiltinExtendedGraphemeClusterLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByExtendedGraphemeClusterLiteral")
public typealias ExtendedGraphemeClusterLiteralConvertible = ExpressibleByExtendedGraphemeClusterLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "_ExpressibleByBuiltinStringLiteral")
public typealias _BuiltinStringLiteralConvertible = _ExpressibleByBuiltinStringLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByStringLiteral")
public typealias StringLiteralConvertible = ExpressibleByStringLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByArrayLiteral")
public typealias ArrayLiteralConvertible = ExpressibleByArrayLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByDictionaryLiteral")
public typealias DictionaryLiteralConvertible = ExpressibleByDictionaryLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "ExpressibleByStringInterpolation")
public typealias StringInterpolationConvertible = ExpressibleByStringInterpolation
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "_ExpressibleByColorLiteral")
public typealias _ColorLiteralConvertible = _ExpressibleByColorLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "_ExpressibleByImageLiteral")
public typealias _ImageLiteralConvertible = _ExpressibleByImageLiteral
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "_ExpressibleByFileReferenceLiteral")
public typealias _FileReferenceLiteralConvertible = _ExpressibleByFileReferenceLiteral
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "ClosedRange.Index")
public typealias ClosedRangeIndex<T> = ClosedRange<T>.Index where T: Strideable, T.Stride: SignedInteger
/// An optional type that allows implicit member access.
///
/// The `ImplicitlyUnwrappedOptional` type is deprecated. To create an optional
/// value that is implicitly unwrapped, place an exclamation mark (`!`) after
/// the type that you want to denote as optional.
///
/// // An implicitly unwrapped optional integer
/// let guaranteedNumber: Int! = 6
///
/// // An optional integer
/// let possibleNumber: Int? = 5
@available(*, unavailable, renamed: "Optional")
public typealias ImplicitlyUnwrappedOptional<Wrapped> = Optional<Wrapped>
extension Range where Bound: Strideable, Bound.Stride: SignedInteger {
/// Now that Range is conditionally a collection when Bound: Strideable,
/// CountableRange is no longer needed. This is a deprecated initializer
/// for any remaining uses of Range(countableRange).
@available(swift, deprecated: 4.2, obsoleted: 5.0, message: "CountableRange is now a Range. No need to convert any more.")
public init(_ other: Range<Bound>) {
self = other
}
}
extension ClosedRange where Bound: Strideable, Bound.Stride: SignedInteger {
/// Now that Range is conditionally a collection when Bound: Strideable,
/// CountableRange is no longer needed. This is a deprecated initializer
/// for any remaining uses of Range(countableRange).
@available(swift, deprecated: 4.2, obsoleted: 5.0, message: "CountableClosedRange is now a ClosedRange. No need to convert any more.")
public init(_ other: ClosedRange<Bound>) {
self = other
}
}
@available(swift, deprecated: 5.0, renamed: "KeyValuePairs")
public typealias DictionaryLiteral<Key, Value> = KeyValuePairs<Key, Value>
extension LazySequenceProtocol {
/// Returns the non-`nil` results of mapping the given transformation over
/// this sequence.
///
/// Use this method to receive a sequence of non-optional values when your
/// transformation produces an optional value.
///
/// - Parameter transform: A closure that accepts an element of this sequence
/// as its argument and returns an optional value.
///
/// - Complexity: O(1)
@available(swift, deprecated: 4.1, renamed: "compactMap(_:)", message: "Please use compactMap(_:) for the case where closure returns an optional value")
public func flatMap<ElementOfResult>(
_ transform: @escaping (Elements.Element) -> ElementOfResult?
) -> LazyMapSequence<
LazyFilterSequence<
LazyMapSequence<Elements, ElementOfResult?>>,
ElementOfResult
> {
return self.compactMap(transform)
}
}
extension String {
/// A view of a string's contents as a collection of characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated: 3.2, obsoleted: 5.0, message: "Please use String directly")
public typealias CharacterView = String
/// A view of the string's contents as a collection of characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated: 3.2, obsoleted: 5.0, message: "Please use String directly")
public var characters: String {
get { return self }
set { self = newValue }
}
/// Applies the given closure to a mutable view of the string's characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated: 3.2, obsoleted: 5.0, message: "Please mutate the String directly")
public mutating func withMutableCharacters<R>(
_ body: (inout String) -> R
) -> R {
return body(&self)
}
}
extension String.UnicodeScalarView: _CustomPlaygroundQuickLookable {
@available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "UnicodeScalarView.customPlaygroundQuickLook will be removed in a future Swift version")
public var customPlaygroundQuickLook: _PlaygroundQuickLook {
return .text(description)
}
}
//===--- Slicing Support --------------------------------------------------===//
// @available(swift,deprecated: 5.0, renamed: "Unicode.UTF8")
public typealias UTF8 = Unicode.UTF8
// @available(swift, deprecated: 5.0, renamed: "Unicode.UTF16")
public typealias UTF16 = Unicode.UTF16
// @available(swift, deprecated: 5.0, renamed: "Unicode.UTF32")
public typealias UTF32 = Unicode.UTF32
// @available(swift, deprecated: 5.0, renamed: "Unicode.Scalar")
public typealias UnicodeScalar = Unicode.Scalar
extension String.UTF16View: _CustomPlaygroundQuickLookable {
@available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "UTF16View.customPlaygroundQuickLook will be removed in a future Swift version")
public var customPlaygroundQuickLook: _PlaygroundQuickLook {
return .text(description)
}
}
extension String.UTF8View: _CustomPlaygroundQuickLookable {
@available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "UTF8View.customPlaygroundQuickLook will be removed in a future Swift version")
public var customPlaygroundQuickLook: _PlaygroundQuickLook {
return .text(description)
}
}
extension Substring {
/// A view of a string's contents as a collection of characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated: 3.2, obsoleted: 5.0, message: "Please use Substring directly")
public typealias CharacterView = Substring
/// A view of the string's contents as a collection of characters.
@available(swift, deprecated: 3.2, obsoleted: 5.0, message: "Please use Substring directly")
public var characters: Substring {
get {
return self
}
set {
self = newValue
}
}
/// Applies the given closure to a mutable view of the string's characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated: 3.2, obsoleted: 5.0, message: "Please mutate the Substring directly")
public mutating func withMutableCharacters<R>(
_ body: (inout Substring) -> R
) -> R {
return body(&self)
}
private func _boundsCheck(_ range: Range<Index>) {
_precondition(range.lowerBound >= startIndex,
"String index range is out of bounds")
_precondition(range.upperBound <= endIndex,
"String index range is out of bounds")
}
}
#if SWIFT_ENABLE_REFLECTION
extension Substring: _CustomPlaygroundQuickLookable {
@available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "Substring.customPlaygroundQuickLook will be removed in a future Swift version")
public var customPlaygroundQuickLook: _PlaygroundQuickLook {
return String(self).customPlaygroundQuickLook
}
}
#endif
extension Collection {
@available(swift, deprecated: 4.0, obsoleted: 5.0, message: "all index distances are now of type Int")
public func index<T: BinaryInteger>(_ i: Index, offsetBy n: T) -> Index {
return index(i, offsetBy: Int(n))
}
@available(swift, deprecated: 4.0, obsoleted: 5.0, message: "all index distances are now of type Int")
public func formIndex<T: BinaryInteger>(_ i: inout Index, offsetBy n: T) {
return formIndex(&i, offsetBy: Int(n))
}
@available(swift, deprecated: 4.0, obsoleted: 5.0, message: "all index distances are now of type Int")
public func index<T: BinaryInteger>(_ i: Index, offsetBy n: T, limitedBy limit: Index) -> Index? {
return index(i, offsetBy: Int(n), limitedBy: limit)
}
@available(swift, deprecated: 4.0, obsoleted: 5.0, message: "all index distances are now of type Int")
public func formIndex<T: BinaryInteger>(_ i: inout Index, offsetBy n: T, limitedBy limit: Index) -> Bool {
return formIndex(&i, offsetBy: Int(n), limitedBy: limit)
}
@available(swift, deprecated: 4.0, obsoleted: 5.0, message: "all index distances are now of type Int")
public func distance<T: BinaryInteger>(from start: Index, to end: Index) -> T {
return numericCast(distance(from: start, to: end) as Int)
}
}
extension UnsafeMutablePointer {
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "initialize(repeating:count:)")
public func initialize(to newValue: Pointee, count: Int = 1) {
initialize(repeating: newValue, count: count)
}
@available(swift, deprecated: 4.1, obsoleted: 5.0, message: "the default argument to deinitialize(count:) has been removed, please specify the count explicitly")
@discardableResult
public func deinitialize() -> UnsafeMutableRawPointer {
return deinitialize(count: 1)
}
@available(swift, deprecated: 4.1, obsoleted: 5.0, message: "Swift currently only supports freeing entire heap blocks, use deallocate() instead")
public func deallocate(capacity _: Int) {
self.deallocate()
}
/// Initializes memory starting at this pointer's address with the elements
/// of the given collection.
///
/// The region of memory starting at this pointer and covering `source.count`
/// instances of the pointer's `Pointee` type must be uninitialized or
/// `Pointee` must be a trivial type. After calling `initialize(from:)`, the
/// region is initialized.
///
/// - Parameter source: A collection of elements of the pointer's `Pointee`
/// type.
// This is fundamentally unsafe since collections can underreport their count.
@available(swift, deprecated: 4.2, obsoleted: 5.0, message: "it will be removed in Swift 5.0. Please use 'UnsafeMutableBufferPointer.initialize(from:)' instead")
public func initialize<C: Collection>(from source: C)
where C.Element == Pointee {
let buf = UnsafeMutableBufferPointer(start: self, count: numericCast(source.count))
var (remainders,writtenUpTo) = source._copyContents(initializing: buf)
// ensure that exactly rhs.count elements were written
_precondition(remainders.next() == nil, "rhs underreported its count")
_precondition(writtenUpTo == buf.endIndex, "rhs overreported its count")
}
}
extension UnsafeMutableRawPointer {
@available(*, unavailable, renamed: "init(mutating:)")
public init(@_nonEphemeral _ from: UnsafeRawPointer) { Builtin.unreachable() }
@available(*, unavailable, renamed: "init(mutating:)")
public init?(@_nonEphemeral _ from: UnsafeRawPointer?) { Builtin.unreachable() }
@available(*, unavailable, renamed: "init(mutating:)")
public init<T>(@_nonEphemeral _ from: UnsafePointer<T>) { Builtin.unreachable() }
@available(*, unavailable, renamed: "init(mutating:)")
public init?<T>(@_nonEphemeral _ from: UnsafePointer<T>?) { Builtin.unreachable() }
}
extension UnsafeRawPointer: _CustomPlaygroundQuickLookable {
internal var summary: String {
let ptrValue = UInt64(
bitPattern: Int64(Int(Builtin.ptrtoint_Word(_rawValue))))
return ptrValue == 0
? "UnsafeRawPointer(nil)"
: "UnsafeRawPointer(0x\(_uint64ToString(ptrValue, radix:16, uppercase:true)))"
}
@available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "UnsafeRawPointer.customPlaygroundQuickLook will be removed in a future Swift version")
public var customPlaygroundQuickLook: _PlaygroundQuickLook {
return .text(summary)
}
}
extension UnsafeMutableRawPointer: _CustomPlaygroundQuickLookable {
private var summary: String {
let ptrValue = UInt64(
bitPattern: Int64(Int(Builtin.ptrtoint_Word(_rawValue))))
return ptrValue == 0
? "UnsafeMutableRawPointer(nil)"
: "UnsafeMutableRawPointer(0x\(_uint64ToString(ptrValue, radix:16, uppercase:true)))"
}
@available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "UnsafeMutableRawPointer.customPlaygroundQuickLook will be removed in a future Swift version")
public var customPlaygroundQuickLook: _PlaygroundQuickLook {
return .text(summary)
}
}
extension UnsafePointer: _CustomPlaygroundQuickLookable {
private var summary: String {
let ptrValue = UInt64(bitPattern: Int64(Int(Builtin.ptrtoint_Word(_rawValue))))
return ptrValue == 0
? "UnsafePointer(nil)"
: "UnsafePointer(0x\(_uint64ToString(ptrValue, radix:16, uppercase:true)))"
}
@available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "UnsafePointer.customPlaygroundQuickLook will be removed in a future Swift version")
public var customPlaygroundQuickLook: PlaygroundQuickLook {
return .text(summary)
}
}
extension UnsafeMutablePointer: _CustomPlaygroundQuickLookable {
private var summary: String {
let ptrValue = UInt64(bitPattern: Int64(Int(Builtin.ptrtoint_Word(_rawValue))))
return ptrValue == 0
? "UnsafeMutablePointer(nil)"
: "UnsafeMutablePointer(0x\(_uint64ToString(ptrValue, radix:16, uppercase:true)))"
}
@available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "UnsafeMutablePointer.customPlaygroundQuickLook will be removed in a future Swift version")
public var customPlaygroundQuickLook: PlaygroundQuickLook {
return .text(summary)
}
}
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "UnsafeBufferPointer.Iterator")
public typealias UnsafeBufferPointerIterator<T> = UnsafeBufferPointer<T>.Iterator
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "UnsafeRawBufferPointer.Iterator")
public typealias UnsafeRawBufferPointerIterator<T> = UnsafeBufferPointer<T>.Iterator
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "UnsafeRawBufferPointer.Iterator")
public typealias UnsafeMutableRawBufferPointerIterator<T> = UnsafeBufferPointer<T>.Iterator
extension UnsafeMutableRawPointer {
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "allocate(byteCount:alignment:)")
public static func allocate(
bytes size: Int, alignedTo alignment: Int
) -> UnsafeMutableRawPointer {
return UnsafeMutableRawPointer.allocate(byteCount: size, alignment: alignment)
}
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "deallocate()", message: "Swift currently only supports freeing entire heap blocks, use deallocate() instead")
public func deallocate(bytes _: Int, alignedTo _: Int) {
self.deallocate()
}
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "copyMemory(from:byteCount:)")
public func copyBytes(from source: UnsafeRawPointer, count: Int) {
copyMemory(from: source, byteCount: count)
}
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "initializeMemory(as:repeating:count:)")
@discardableResult
public func initializeMemory<T>(
as type: T.Type, at offset: Int = 0, count: Int = 1, to repeatedValue: T
) -> UnsafeMutablePointer<T> {
return (self + offset * MemoryLayout<T>.stride).initializeMemory(
as: type, repeating: repeatedValue, count: count)
}
@available(swift, deprecated: 4.1, obsoleted: 5.0, message: "it will be removed in Swift 5.0. Please use 'UnsafeMutableRawBufferPointer.initialize(from:)' instead")
@discardableResult
public func initializeMemory<C: Collection>(
as type: C.Element.Type, from source: C
) -> UnsafeMutablePointer<C.Element> {
// TODO: Optimize where `C` is a `ContiguousArrayBuffer`.
// Initialize and bind each element of the container.
var ptr = self
for element in source {
ptr.initializeMemory(as: C.Element.self, repeating: element, count: 1)
ptr += MemoryLayout<C.Element>.stride
}
return UnsafeMutablePointer(_rawValue)
}
}
extension UnsafeMutableRawBufferPointer {
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "allocate(byteCount:alignment:)")
public static func allocate(count: Int) -> UnsafeMutableRawBufferPointer {
return UnsafeMutableRawBufferPointer.allocate(
byteCount: count, alignment: MemoryLayout<UInt>.alignment)
}
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "copyMemory(from:)")
public func copyBytes(from source: UnsafeRawBufferPointer) {
copyMemory(from: source)
}
}
//===----------------------------------------------------------------------===//
// The following overloads of flatMap are carefully crafted to allow the code
// like the following:
// ["hello"].flatMap { $0 }
// return an array of strings without any type context in Swift 3 mode, at the
// same time allowing the following code snippet to compile:
// [0, 1].flatMap { x in
// if String(x) == "foo" { return "bar" } else { return nil }
// }
// Note that the second overload is declared on a more specific protocol.
// See: test/stdlib/StringFlatMap.swift for tests.
extension Sequence {
@available(swift, deprecated: 4.1/*, obsoleted: 5.1 */, renamed: "compactMap(_:)",
message: "Please use compactMap(_:) for the case where closure returns an optional value")
public func flatMap<ElementOfResult>(
_ transform: (Element) throws -> ElementOfResult?
) rethrows -> [ElementOfResult] {
return try _compactMap(transform)
}
}
extension Collection {
@available(swift, deprecated: 4.1, obsoleted: 5.0, renamed: "compactMap(_:)",
message: "Please use compactMap(_:) for the case where closure returns an optional value")
public func flatMap(
_ transform: (Element) throws -> String?
) rethrows -> [String] {
return try _compactMap(transform)
}
}
extension Collection {
/// Returns the first index in which an element of the collection satisfies
/// the given predicate.
@available(swift, deprecated: 5.0, renamed: "firstIndex(where:)")
@inlinable
public func index(
where _predicate: (Element) throws -> Bool
) rethrows -> Index? {
return try firstIndex(where: _predicate)
}
}
extension Collection where Element: Equatable {
/// Returns the first index where the specified value appears in the
/// collection.
@available(swift, deprecated: 5.0, renamed: "firstIndex(of:)")
@inlinable
public func index(of element: Element) -> Index? {
return firstIndex(of: element)
}
}
extension Zip2Sequence {
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "Sequence1.Iterator")
public typealias Stream1 = Sequence1.Iterator
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "Sequence2.Iterator")
public typealias Stream2 = Sequence2.Iterator
}
//===--- QuickLooks -------------------------------------------------------===//
/// The sum of types that can be used as a Quick Look representation.
///
/// The `PlaygroundQuickLook` protocol is deprecated, and will be removed from
/// the standard library in a future Swift release. To customize the logging of
/// your type in a playground, conform to the
/// `CustomPlaygroundDisplayConvertible` protocol, which does not use the
/// `PlaygroundQuickLook` enum.
///
/// If you need to provide a customized playground representation in Swift 4.0
/// or Swift 3.2 or earlier, use a conditional compilation block:
///
/// #if swift(>=4.1) || (swift(>=3.3) && !swift(>=4.0))
/// // With Swift 4.1 and later (including Swift 3.3 and later), use
/// // the CustomPlaygroundDisplayConvertible protocol.
/// #else
/// // With Swift 4.0 and Swift 3.2 and earlier, use PlaygroundQuickLook
/// // and the CustomPlaygroundQuickLookable protocol.
/// #endif
@available(swift, deprecated: 4.2, message: "PlaygroundQuickLook will be removed in a future Swift version. For customizing how types are presented in playgrounds, use CustomPlaygroundDisplayConvertible instead.")
public typealias PlaygroundQuickLook = _PlaygroundQuickLook
@frozen // rdar://problem/38719739 - needed by LLDB
public enum _PlaygroundQuickLook {
case text(String)
case int(Int64)
case uInt(UInt64)
case float(Float32)
case double(Float64)
case image(Any)
case sound(Any)
case color(Any)
case bezierPath(Any)
case attributedString(Any)
case rectangle(Float64, Float64, Float64, Float64)
case point(Float64, Float64)
case size(Float64, Float64)
case bool(Bool)
case range(Int64, Int64)
case view(Any)
case sprite(Any)
case url(String)
case _raw([UInt8], String)
}
@available(*, unavailable)
extension _PlaygroundQuickLook: Sendable {}
#if SWIFT_ENABLE_REFLECTION
extension _PlaygroundQuickLook {
/// Creates a new Quick Look for the given instance.
///
/// If the dynamic type of `subject` conforms to
/// `CustomPlaygroundQuickLookable`, the result is found by calling its
/// `customPlaygroundQuickLook` property. Otherwise, the result is
/// synthesized by the language. In some cases, the synthesized result may
/// be `.text(String(reflecting: subject))`.
///
/// - Note: If the dynamic type of `subject` has value semantics, subsequent
/// mutations of `subject` will not observable in the Quick Look. In
/// general, though, the observability of such mutations is unspecified.
///
/// - Parameter subject: The instance to represent with the resulting Quick
/// Look.
@available(swift, deprecated: 4.2, obsoleted: 5.0, message: "PlaygroundQuickLook will be removed in a future Swift version.")
public init(reflecting subject: Any) {
if let customized = subject as? _CustomPlaygroundQuickLookable {
self = customized.customPlaygroundQuickLook
}
else if let customized = subject as? __DefaultCustomPlaygroundQuickLookable {
self = customized._defaultCustomPlaygroundQuickLook
}
else {
if let q = Mirror.quickLookObject(subject) {
self = q
}
else {
self = .text(String(reflecting: subject))
}
}
}
}
#endif
/// A type that explicitly supplies its own playground Quick Look.
///
/// The `CustomPlaygroundQuickLookable` protocol is deprecated, and will be
/// removed from the standard library in a future Swift release. To customize
/// the logging of your type in a playground, conform to the
/// `CustomPlaygroundDisplayConvertible` protocol.
///
/// If you need to provide a customized playground representation in Swift 4.0
/// or Swift 3.2 or earlier, use a conditional compilation block:
///
/// #if swift(>=4.1) || (swift(>=3.3) && !swift(>=4.0))
/// // With Swift 4.1 and later (including Swift 3.3 and later),
/// // conform to CustomPlaygroundDisplayConvertible.
/// extension MyType: CustomPlaygroundDisplayConvertible { /*...*/ }
/// #else
/// // Otherwise, on Swift 4.0 and Swift 3.2 and earlier,
/// // conform to CustomPlaygroundQuickLookable.
/// extension MyType: CustomPlaygroundQuickLookable { /*...*/ }
/// #endif
@available(swift, deprecated: 4.2, obsoleted: 5.0, message: "CustomPlaygroundQuickLookable will be removed in a future Swift version. For customizing how types are presented in playgrounds, use CustomPlaygroundDisplayConvertible instead.")
public typealias CustomPlaygroundQuickLookable = _CustomPlaygroundQuickLookable
//@available(swift, obsoleted: 5.0)
public protocol _CustomPlaygroundQuickLookable {
/// A custom playground Quick Look for this instance.
///
/// If this type has value semantics, the `PlaygroundQuickLook` instance
/// should be unaffected by subsequent mutations.
var customPlaygroundQuickLook: _PlaygroundQuickLook { get }
}
// Double-underscored real version allows us to keep using this in AppKit while
// warning for non-SDK use. This is probably overkill but it doesn't cost
// anything.
@available(swift, deprecated: 4.2, obsoleted: 5.0, message: "_DefaultCustomPlaygroundQuickLookable will be removed in a future Swift version. For customizing how types are presented in playgrounds, use CustomPlaygroundDisplayConvertible instead.")
public typealias _DefaultCustomPlaygroundQuickLookable = __DefaultCustomPlaygroundQuickLookable
// @available(swift, obsoleted: 5.0)
public protocol __DefaultCustomPlaygroundQuickLookable {
var _defaultCustomPlaygroundQuickLook: _PlaygroundQuickLook { get }
}
extension String {
/// A type that represents the number of steps between two `String.Index`
/// values, where one value is reachable from the other.
///
/// In Swift, *reachability* refers to the ability to produce one value from
/// the other through zero or more applications of `index(after:)`.
@available(*, deprecated, message: "All index distances are now of type Int")
public typealias IndexDistance = Int
}
|