-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Range.swift.gyb
741 lines (680 loc) · 24.4 KB
/
Range.swift.gyb
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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
//===--- Range.swift.gyb --------------------------------------*- swift -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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
//
//===----------------------------------------------------------------------===//
// FIXME(ABI)#55 (Statically Unavailable/Dynamically Available): remove this type, it creates an ABI burden
// on the library.
//
// A dummy type that we can use when we /don't/ want to create an
// ambiguity indexing CountableRange<T> outside a generic context.
public enum _DisabledRangeIndex_ {}
/// A half-open range that forms a collection of consecutive values.
///
/// You create a `CountableRange` instance by using the half-open range
/// operator (`..<`).
///
/// let upToFive = 0..<5
///
/// The associated `Bound` type is both the element and index type of
/// `CountableRange`. Each element of the range is its own corresponding
/// index. The lower bound of a `CountableRange` instance is its start index,
/// and the upper bound is its end index.
///
/// print(upToFive.contains(3)) // Prints "true"
/// print(upToFive.contains(10)) // Prints "false"
/// print(upToFive.contains(5)) // Prints "false"
///
/// If the `Bound` type has a maximal value, it can serve as an upper bound but
/// can never be contained in a `CountableRange<Bound>` instance. For example,
/// a `CountableRange<Int8>` instance can use `Int8.max` as its upper bound,
/// but it can't represent a range that includes `Int8.max`.
///
/// let maximumRange = Int8.min..<Int8.max
/// print(maximumRange.contains(Int8.max))
/// // Prints "false"
///
/// If you need to create a range that includes the maximal value of its
/// `Bound` type, see the `CountableClosedRange` type.
///
/// You can create a countable range over any type that conforms to the
/// `Strideable` protocol and uses an integer as its associated `Stride` type.
/// By default, Swift's integer and pointer types are usable as the bounds of
/// a countable range.
///
/// Because floating-point types such as `Float` and `Double` are their own
/// `Stride` types, they cannot be used as the bounds of a countable range. If
/// you need to test whether values are contained within an interval bound by
/// floating-point values, see the `Range` type. If you need to iterate over
/// consecutive floating-point values, see the `stride(from:to:by:)` function.
///
/// Integer Index Ambiguity
/// -----------------------
///
/// Because each element of a `CountableRange` instance is its own index, for
/// the range `(-99..<100)` the element at index `0` is `0`. This is an
/// unexpected result for those accustomed to zero-based collection indices,
/// who might expect the result to be `-99`. To prevent this confusion, in a
/// context where `Bound` is known to be an integer type, subscripting
/// directly is a compile-time error:
///
/// // error: ambiguous use of 'subscript'
/// print((-99..<100)[0])
///
/// However, subscripting that range still works in a generic context:
///
/// func brackets<T>(_ x: CountableRange<T>, _ i: T) -> T {
/// return x[i] // Just forward to subscript
/// }
/// print(brackets(-99..<100, 0))
/// // Prints "0"
///
/// - SeeAlso: `CountableClosedRange`, `Range`, `ClosedRange`
@_fixed_layout
public struct CountableRange<Bound> : RandomAccessCollection
where
// FIXME(ABI)#176 (Type checker)
// WORKAROUND rdar://25214598 - should be just Bound : Strideable
Bound : _Strideable & Comparable,
Bound.Stride : SignedInteger {
/// The range's lower bound.
///
/// In an empty range, `lowerBound` is equal to `upperBound`.
public let lowerBound: Bound
/// The range's upper bound.
///
/// `upperBound` is not a valid subscript argument and is always
/// reachable from `lowerBound` by zero or more applications of
/// `index(after:)`.
///
/// In an empty range, `upperBound` is equal to `lowerBound`.
public let upperBound: Bound
/// The bound type of the range.
public typealias Element = Bound
/// A type that represents a position in the range.
public typealias Index = Element
public typealias IndexDistance = Bound.Stride
@_inlineable
public var startIndex: Index {
return lowerBound
}
@_inlineable
public var endIndex: Index {
return upperBound
}
@_inlineable
public func index(after i: Index) -> Index {
_failEarlyRangeCheck(i, bounds: startIndex..<endIndex)
return i.advanced(by: 1)
}
@_inlineable
public func index(before i: Index) -> Index {
_precondition(i > lowerBound)
_precondition(i <= upperBound)
return i.advanced(by: -1)
}
@_inlineable
public func index(_ i: Index, offsetBy n: IndexDistance) -> Index {
let r = i.advanced(by: n)
_precondition(r >= lowerBound)
_precondition(r <= upperBound)
return r
}
@_inlineable
public func distance(from start: Index, to end: Index) -> IndexDistance {
return start.distance(to: end)
}
public typealias SubSequence = CountableRange<Bound>
/// Accesses the subsequence bounded by the given range.
///
/// - Parameter bounds: A range of the range's indices. The upper and lower
/// bounds of the `bounds` range must be valid indices of the collection.
@_inlineable
public subscript(bounds: Range<Index>) -> CountableRange<Bound> {
return CountableRange(bounds)
}
/// Accesses the subsequence bounded by the given range.
///
/// - Parameter bounds: A range of the range's indices. The upper and lower
/// bounds of the `bounds` range must be valid indices of the collection.
@_inlineable
public subscript(bounds: CountableRange<Bound>) -> CountableRange<Bound> {
return self[Range(bounds)]
}
public typealias Indices = CountableRange<Bound>
/// The indices that are valid for subscripting the range, in ascending
/// order.
@_inlineable
public var indices: Indices {
return self
}
/// Creates an instance with the given bounds.
///
/// Because this initializer does not perform any checks, it should be used
/// as an optimization only when you are absolutely certain that `lower` is
/// less than or equal to `upper`. Using the half-open range operator
/// (`..<`) to form `CountableRange` instances is preferred.
///
/// - Parameter bounds: A tuple of the lower and upper bounds of the range.
@_inlineable
public init(uncheckedBounds bounds: (lower: Bound, upper: Bound)) {
self.lowerBound = bounds.lower
self.upperBound = bounds.upper
}
@_inlineable
public func _customContainsEquatableElement(_ element: Element) -> Bool? {
return lowerBound <= element && element < upperBound
}
/// A Boolean value indicating whether the range contains no elements.
///
/// An empty range has equal lower and upper bounds.
///
/// let empty = 10..<10
/// print(empty.isEmpty)
/// // Prints "true"
@_inlineable
public var isEmpty: Bool {
return lowerBound == upperBound
}
}
//===--- Protection against 0-based indexing assumption -------------------===//
// The following two extensions provide subscript overloads that
// create *intentional* ambiguities to prevent the use of integers as
// indices for ranges, outside a generic context. This prevents mistakes
// such as x = r[0], which will trap unless 0 happens to be contained in the
// range r.
//
// FIXME(ABI)#56 (Statically Unavailable/Dynamically Available): remove this code, it creates an ABI burden
// on the library.
extension CountableRange {
/// Accesses the element at specified position.
///
/// You can subscript a collection with any valid index other than the
/// collection's end index. The end index refers to the position one past
/// the last element of a collection, so it doesn't correspond with an
/// element.
///
/// - Parameter position: The position of the element to access. `position`
/// must be a valid index of the range, and must not equal the range's end
/// index.
@_inlineable
public subscript(position: Index) -> Element {
// FIXME: swift-3-indexing-model: tests for the range check.
_debugPrecondition(self.contains(position), "Index out of range")
return position
}
public subscript(_position: Bound._DisabledRangeIndex) -> Element {
fatalError("uncallable")
}
}
extension CountableRange
where
Bound._DisabledRangeIndex : Strideable,
Bound._DisabledRangeIndex.Stride : SignedInteger {
public subscript(
_bounds: Range<Bound._DisabledRangeIndex>
) -> CountableRange<Bound> {
fatalError("uncallable")
}
public subscript(
_bounds: CountableRange<Bound._DisabledRangeIndex>
) -> CountableRange<Bound> {
fatalError("uncallable")
}
public subscript(
_bounds: ClosedRange<Bound._DisabledRangeIndex>
) -> CountableRange<Bound> {
fatalError("uncallable")
}
public subscript(
_bounds: CountableClosedRange<Bound._DisabledRangeIndex>
) -> CountableRange<Bound> {
fatalError("uncallable")
}
/// Accesses the subsequence bounded by the given range.
///
/// - Parameter bounds: A range of the collection's indices. The upper and
/// lower bounds of the `bounds` range must be valid indices of the
/// collection and `bounds.upperBound` must be less than the collection's
/// end index.
@_inlineable
public subscript(bounds: ClosedRange<Bound>) -> CountableRange<Bound> {
return self[bounds.lowerBound..<(bounds.upperBound.advanced(by: 1))]
}
/// Accesses the subsequence bounded by the given range.
///
/// - Parameter bounds: A range of the collection's indices. The upper and
/// lower bounds of the `bounds` range must be valid indices of the
/// collection and `bounds.upperBound` must be less than the collection's
/// end index.
@_inlineable
public subscript(
bounds: CountableClosedRange<Bound>
) -> CountableRange<Bound> {
return self[ClosedRange(bounds)]
}
}
//===--- End 0-based indexing protection ----------------------------------===//
/// A half-open interval over a comparable type, from a lower bound up to, but
/// not including, an upper bound.
///
/// You create `Range` instances by using the half-open range operator (`..<`).
///
/// let underFive = 0.0..<5.0
///
/// You can use a `Range` instance to quickly check if a value is contained in
/// a particular range of values. For example:
///
/// print(underFive.contains(3.14)) // Prints "true"
/// print(underFive.contains(6.28)) // Prints "false"
/// print(underFive.contains(5.0)) // Prints "false"
///
/// `Range` instances can represent an empty interval, unlike `ClosedRange`.
///
/// let empty = 0.0..<0.0
/// print(empty.contains(0.0)) // Prints "false"
/// print(empty.isEmpty) // Prints "true"
///
/// - SeeAlso: `CountableRange`, `ClosedRange`, `CountableClosedRange`
@_fixed_layout
public struct Range<
Bound : Comparable
> {
/// Creates an instance with the given bounds.
///
/// Because this initializer does not perform any checks, it should be used
/// as an optimization only when you are absolutely certain that `lower` is
/// less than or equal to `upper`. Using the half-open range operator
/// (`..<`) to form `Range` instances is preferred.
///
/// - Parameter bounds: A tuple of the lower and upper bounds of the range.
@_inlineable
public init(uncheckedBounds bounds: (lower: Bound, upper: Bound)) {
self.lowerBound = bounds.lower
self.upperBound = bounds.upper
}
/// The range's lower bound.
///
/// In an empty range, `lowerBound` is equal to `upperBound`.
public let lowerBound: Bound
/// The range's upper bound.
///
/// In an empty range, `upperBound` is equal to `lowerBound`. A `Range`
/// instance does not contain its upper bound.
public let upperBound: Bound
/// Returns a Boolean value indicating whether the given element is contained
/// within the range.
///
/// Because `Range` represents a half-open range, a `Range` instance does not
/// contain its upper bound. `element` is contained in the range if it is
/// greater than or equal to the lower bound and less than the upper bound.
///
/// - Parameter element: The element to check for containment.
/// - Returns: `true` if `element` is contained in the range; otherwise,
/// `false`.
@_inlineable
public func contains(_ element: Bound) -> Bool {
return lowerBound <= element && element < upperBound
}
/// A Boolean value indicating whether the range contains no elements.
///
/// An empty `Range` instance has equal lower and upper bounds.
///
/// let empty: Range = 10..<10
/// print(empty.isEmpty)
/// // Prints "true"
@_inlineable
public var isEmpty: Bool {
return lowerBound == upperBound
}
}
%{
all_range_types = [
('Range', '..<'),
('CountableRange', '..<'),
('ClosedRange', '...'),
('CountableClosedRange', '...')
]
def get_init_warning(Self, OtherSelf):
if 'Closed' in Self and 'Closed' not in OtherSelf:
return """\
///
/// An equivalent range must be representable as an instance of `%s`.
/// For example, passing an empty range as `other` triggers a runtime error,
/// because an empty range cannot be represented by a `%s` instance.\
""" % (Self, Self)
elif 'Closed' not in Self and 'Closed' in OtherSelf:
return """\
///
/// An equivalent range must be representable as an instance of `%s`.
/// For example, passing a closed range with an upper bound of `Int.max`
/// triggers a runtime error, because the resulting half-open range would
/// require an upper bound of `Int.max + 1`, which is not representable as
/// an `Int`.\
""" % Self
else:
return ""
}%
% for (Self, op) in all_range_types:
% for (OtherSelf, other_op) in all_range_types:
extension ${Self}
% if ('Countable' in OtherSelf or 'Closed' in OtherSelf or 'Closed' in Self) and not 'Countable' in Self:
where
Bound : _Strideable, Bound.Stride : SignedInteger
% end
{
/// Creates an instance equivalent to the given range.
${get_init_warning(Self, OtherSelf)}
///
/// - Parameter other: A range to convert to a `${Self}` instance.
@inline(__always)
public init(_ other: ${OtherSelf}<Bound>) {
% if 'Closed' not in Self and 'Closed' in OtherSelf:
let upperBound = other.upperBound.advanced(by: 1)
% elif 'Closed' in Self and 'Closed' not in OtherSelf:
_precondition(!other.isEmpty, "Can't form an empty closed range")
let upperBound = other.upperBound.advanced(by: -1)
% else:
let upperBound = other.upperBound
% end
self.init(
uncheckedBounds: (lower: other.lowerBound, upper: upperBound)
)
}
}
extension ${Self}
% if 'Countable' in OtherSelf and not 'Countable' in Self:
where
Bound : _Strideable, Bound.Stride : SignedInteger
% end
{
/// Returns a Boolean value indicating whether this range and the given range
/// contain an element in common.
///
/// This example shows two overlapping ranges:
///
/// let x: ${Self} = 0${op}20
/// print(x.overlaps(10${other_op}1000 as ${OtherSelf}))
/// // Prints "true"
///
% if 'Closed' in Self:
/// Because a closed range includes its upper bound, the ranges in the
/// following example also overlap:
///
/// let y: ${OtherSelf} = 20${op}30
/// print(x.overlaps(y))
/// // Prints "true"
% else:
/// Because a half-open range does not include its upper bound, the ranges
/// in the following example do not overlap:
///
/// let y: ${OtherSelf} = 20${op}30
/// print(x.overlaps(y))
/// // Prints "false"
% end
///
/// - Parameter other: A range to check for elements in common.
/// - Returns: `true` if this range and `other` have at least one element in
/// common; otherwise, `false`.
@inline(__always)
public func overlaps(_ other: ${OtherSelf}<Bound>) -> Bool {
return (!other.isEmpty && self.contains(other.lowerBound))
|| (!self.isEmpty && other.contains(lowerBound))
}
}
% end
extension ${Self} {
/// Returns a copy of this range clamped to the given limiting range.
///
/// The bounds of the result are always limited to the bounds of `limits`.
/// For example:
///
/// let x: ${Self} = 0${op}20
/// print(x.clamped(to: 10${op}1000))
/// // Prints "10${op}20"
///
% if 'Closed' in Self:
/// If the two ranges do not overlap, the result is a single-element range at
/// the upper or lower bound of `limits`.
% else:
/// If the two ranges do not overlap, the result is an empty range within the
/// bounds of `limits`.
% end
///
/// let y: ${Self} = 0${op}5
/// print(y.clamped(to: 10${op}1000))
/// // Prints "10${op}10"
///
/// - Parameter limits: The range to clamp the bounds of this range.
/// - Returns: A new range clamped to the bounds of `limits`.
@inline(__always)
public func clamped(to limits: ${Self}) -> ${Self} {
return ${Self}(
uncheckedBounds: (
lower:
limits.lowerBound > self.lowerBound ? limits.lowerBound
: limits.upperBound < self.lowerBound ? limits.upperBound
: self.lowerBound,
upper:
limits.upperBound < self.upperBound ? limits.upperBound
: limits.lowerBound > self.upperBound ? limits.lowerBound
: self.upperBound
)
)
}
}
extension ${Self} : CustomStringConvertible {
/// A textual representation of the range.
public var description: String {
return "\(lowerBound)${op}\(upperBound)"
}
}
extension ${Self} : CustomDebugStringConvertible {
/// A textual representation of the range, suitable for debugging.
public var debugDescription: String {
return "${Self}(\(String(reflecting: lowerBound))"
+ "${op}\(String(reflecting: upperBound)))"
}
}
extension ${Self} : CustomReflectable {
public var customMirror: Mirror {
return Mirror(
self, children: ["lowerBound": lowerBound, "upperBound": upperBound])
}
}
extension ${Self} : Equatable {
/// Returns a Boolean value indicating whether two ranges are equal.
///
/// Two ranges are equal when they have the same lower and upper bounds.
% if 'Closed' in Self:
///
/// let x: ${Self} = 5...15
/// print(x == 5...15)
/// // Prints "true"
/// print(x == 10...20)
/// // Prints "false"
% else:
/// That requirement holds even for empty ranges.
///
/// let x: ${Self} = 5..<15
/// print(x == 5..<15)
/// // Prints "true"
///
/// let y: ${Self} = 5..<5
/// print(y == 15..<15)
/// // Prints "false"
% end
///
/// - Parameters:
/// - lhs: A range to compare.
/// - rhs: Another range to compare.
@_inlineable
public static func == (lhs: ${Self}<Bound>, rhs: ${Self}<Bound>) -> Bool {
return
lhs.lowerBound == rhs.lowerBound &&
lhs.upperBound == rhs.upperBound
}
/// Returns a Boolean value indicating whether a value is included in a
/// range.
///
/// You can use this pattern matching operator (`~=`) to test whether a value
/// is included in a range. The following example uses the `~=` operator to
/// test whether an integer is included in a range of single-digit numbers.
///
/// let chosenNumber = 3
% if 'Closed' in Self:
/// if 0...9 ~= chosenNumber {
% else:
/// if 0..<10 ~= chosenNumber {
% end
/// print("\(chosenNumber) is a single digit.")
/// }
/// // Prints "3 is a single digit."
///
/// The `~=` operator is used internally in `case` statements for pattern
/// matching. When you match against a range in a `case` statement, this
/// operator is called behind the scenes.
///
/// switch chosenNumber {
% if 'Closed' in Self:
/// case 0...9:
% else:
/// case 0..<10:
% end
/// print("\(chosenNumber) is a single digit.")
/// case Int.min..<0:
/// print("\(chosenNumber) is negative.")
/// default:
/// print("\(chosenNumber) is positive.")
/// }
/// // Prints "3 is a single digit."
///
/// - Parameters:
/// - lhs: A range.
/// - rhs: A value to match against `lhs`.
@_inlineable
public static func ~= (pattern: ${Self}<Bound>, value: Bound) -> Bool {
return pattern.contains(value)
}
}
% end
% for Self in [
% 'Range',
% 'ClosedRange',
% ]:
// FIXME(ABI)#57 (Conditional Conformance): replace this extension with a conditional
// conformance.
// rdar://problem/17144340
/// Ranges whose `Bound` is `Strideable` with `Integer` `Stride` have all
/// the capabilities of `RandomAccessCollection`s, just like
/// `CountableRange` and `CountableClosedRange`.
///
/// Unfortunately, we can't forward the full collection API, so we are
/// forwarding a few select APIs.
extension ${Self} where Bound : _Strideable, Bound.Stride : SignedInteger {
// FIXME(ABI)#176 (Type checker)
// WORKAROUND rdar://25214598 - should be Bound : Strideable
/// The number of values contained in the range.
@_inlineable
public var count: Bound.Stride {
let distance = lowerBound.distance(to: upperBound)
% if 'Closed' in Self:
return distance + 1
% else:
return distance
% end
}
}
% end
/// Returns a half-open range that contains its lower bound but not its upper
/// bound.
///
/// Use the half-open range operator (`..<`) to create a range of any type that
/// conforms to the `Comparable` protocol. This example creates a
/// `Range<Double>` from zero up to, but not including, 5.0.
///
/// let lessThanFive = 0.0..<5.0
/// print(lessThanFive.contains(3.14)) // Prints "true"
/// print(lessThanFive.contains(5.0)) // Prints "false"
///
/// - Parameters:
/// - minimum: The lower bound for the range.
/// - maximum: The upper bound for the range.
@_transparent
public func ..< <Bound>(minimum: Bound, maximum: Bound)
-> Range<Bound> {
_precondition(minimum <= maximum,
"Can't form Range with upperBound < lowerBound")
return Range(uncheckedBounds: (lower: minimum, upper: maximum))
}
/// Returns a countable half-open range that contains its lower bound but not
/// its upper bound.
///
/// Use the half-open range operator (`..<`) to create a range of any type that
/// conforms to the `Strideable` protocol with an associated integer `Stride`
/// type, such as any of the standard library's integer types. This example
/// creates a `CountableRange<Int>` from zero up to, but not including, 5.
///
/// let upToFive = 0..<5
/// print(upToFive.contains(3)) // Prints "true"
/// print(upToFive.contains(5)) // Prints "false"
///
/// You can use sequence or collection methods on the `upToFive` countable
/// range.
///
/// print(upToFive.count) // Prints "5"
/// print(upToFive.last) // Prints "4"
///
/// - Parameters:
/// - minimum: The lower bound for the range.
/// - maximum: The upper bound for the range.
@_transparent
public func ..< <Bound>(
minimum: Bound, maximum: Bound
) -> CountableRange<Bound> {
// FIXME: swift-3-indexing-model: tests for traps.
_precondition(minimum <= maximum,
"Can't form Range with upperBound < lowerBound")
return CountableRange(uncheckedBounds: (lower: minimum, upper: maximum))
}
// swift-3-indexing-model: this is not really a proper rename
@available(*, unavailable, renamed: "IndexingIterator")
public struct RangeGenerator<Bound> {}
extension Range {
@available(*, unavailable, renamed: "lowerBound")
public var startIndex: Bound {
Builtin.unreachable()
}
@available(*, unavailable, renamed: "upperBound")
public var endIndex: Bound {
Builtin.unreachable()
}
}
extension ClosedRange {
@available(*, unavailable, message: "Call clamped(to:) and swap the argument and the receiver. For example, x.clamp(y) becomes y.clamped(to: x) in Swift 3.")
public func clamp(
_ intervalToClamp: ClosedRange<Bound>
) -> ClosedRange<Bound> {
Builtin.unreachable()
}
}
extension CountableClosedRange {
@available(*, unavailable, message: "Call clamped(to:) and swap the argument and the receiver. For example, x.clamp(y) becomes y.clamped(to: x) in Swift 3.")
public func clamp(
_ intervalToClamp: CountableClosedRange<Bound>
) -> CountableClosedRange<Bound> {
Builtin.unreachable()
}
}
@available(*, unavailable, message: "IntervalType has been removed in Swift 3. Use ranges instead.")
public typealias IntervalType = Void
@available(*, unavailable, renamed: "Range")
public struct HalfOpenInterval<Bound> {}
@available(*, unavailable, renamed: "ClosedRange")
public struct ClosedInterval<Bound> {}