File tree Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -49,8 +49,6 @@ extension MutableCollection where Self: BidirectionalCollection {
49
49
/// * `c.reversed()` does not create new storage
50
50
/// * `c.reversed().map(f)` maps eagerly and returns a new array
51
51
/// * `c.lazy.reversed().map(f)` maps lazily and returns a `LazyMapCollection`
52
- ///
53
- /// - See also: `ReversedRandomAccessCollection`
54
52
@_fixed_layout
55
53
public struct ReversedCollection < Base: BidirectionalCollection > {
56
54
public let _base : Base
@@ -84,7 +82,7 @@ extension ReversedCollection {
84
82
}
85
83
}
86
84
}
87
-
85
+
88
86
extension ReversedCollection . Iterator : IteratorProtocol , Sequence {
89
87
public typealias Element = Base . Element
90
88
@@ -253,6 +251,17 @@ extension ReversedCollection: BidirectionalCollection {
253
251
254
252
extension ReversedCollection : RandomAccessCollection where Base: RandomAccessCollection { }
255
253
254
+ extension ReversedCollection {
255
+ /// Reversing a reversed collection returns the original collection.
256
+ ///
257
+ /// - Complexity: O(1)
258
+ @inlinable
259
+ @available ( swift, introduced: 4.2 )
260
+ public func reversed( ) -> Base {
261
+ return _base
262
+ }
263
+ }
264
+
256
265
extension BidirectionalCollection {
257
266
/// Returns a view presenting the elements of the collection in reverse
258
267
/// order.
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
3
+ // RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
4
+ // RUN: %target-build-swift %s -o %t/a.out5 -swift-version 5 && %target-run %t/a.out5
5
+ // REQUIRES: executable_test
6
+
7
+ import StdlibUnittest
8
+
9
+ #if swift(>=4.2)
10
+ let swiftVersion = " >=4.2 "
11
+ #else
12
+ let swiftVersion = " <4.2 "
13
+ #endif
14
+
15
+ let tests = TestSuite ( " ReverseCompatibility " )
16
+
17
+ tests. test ( " Double reverse type/Collection/ \( swiftVersion) " ) {
18
+ func reverse< C : BidirectionalCollection > ( _ xs: C ) {
19
+ var result = xs. reversed ( ) . reversed ( )
20
+ #if swift(>=4.2)
21
+ expectType ( C . self, & result)
22
+ #else
23
+ expectType ( ReversedCollection< ReversedCollection< C>>. self , & result)
24
+ #endif
25
+ }
26
+ reverse ( Array ( 0 ..< 10 ) )
27
+
28
+ func backwardCompatible< C : BidirectionalCollection > ( _ xs: C ) {
29
+ typealias ExpectedType = ReversedCollection < ReversedCollection < C > >
30
+ var result : ExpectedType = xs. reversed ( ) . reversed ( )
31
+ expectType ( ExpectedType . self, & result)
32
+ }
33
+ backwardCompatible ( Array ( 0 ..< 10 ) )
34
+ }
35
+
36
+ runAllTests ( )
You can’t perform that action at this time.
0 commit comments