mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This adds a pair of Swift protocols that represents C++ iterator types conforming to `std::contiguous_iterator_tag` requirements. These are random access iterators that guarantee that the values are stored in consequent memory addresses. This will be used to optimize usage of C++ containers such as `std::vector` from Swift, for instance, by providing an overload of `withContiguousStorageIfAvailable` for contiguous containers. rdar://137877849
29 lines
1.5 KiB
Swift
29 lines
1.5 KiB
Swift
// RUN: %target-swift-ide-test -print-module -module-to-print=CustomIterator -source-filename=x -I %S/Inputs -cxx-interoperability-mode=swift-6 -Xcc -std=c++20 | %FileCheck %s
|
|
// RUN: %target-swift-ide-test -print-module -module-to-print=CustomIterator -source-filename=x -I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++20 | %FileCheck %s
|
|
|
|
// Ubuntu 20.04 ships with an old version of libstdc++, which does not provide
|
|
// std::contiguous_iterator_tag from C++20.
|
|
// UNSUPPORTED: LinuxDistribution=ubuntu-20.04
|
|
// UNSUPPORTED: LinuxDistribution=amzn-2
|
|
|
|
// CHECK: struct ConstContiguousIterator : UnsafeCxxContiguousIterator, UnsafeCxxRandomAccessIterator, UnsafeCxxInputIterator {
|
|
// CHECK: func successor() -> ConstContiguousIterator
|
|
// CHECK: var pointee: Int32
|
|
// CHECK: typealias Pointee = Int32
|
|
// CHECK: typealias Distance = Int32
|
|
// CHECK: }
|
|
|
|
// CHECK: struct HasCustomContiguousIteratorTag : UnsafeCxxContiguousIterator, UnsafeCxxRandomAccessIterator, UnsafeCxxInputIterator {
|
|
// CHECK: func successor() -> HasCustomContiguousIteratorTag
|
|
// CHECK: var pointee: Int32
|
|
// CHECK: typealias Pointee = Int32
|
|
// CHECK: typealias Distance = Int32
|
|
// CHECK: }
|
|
|
|
// CHECK: struct MutableContiguousIterator : UnsafeCxxMutableContiguousIterator, UnsafeCxxMutableRandomAccessIterator, UnsafeCxxMutableInputIterator {
|
|
// CHECK: func successor() -> MutableContiguousIterator
|
|
// CHECK: var pointee: Int32
|
|
// CHECK: typealias Pointee = Int32
|
|
// CHECK: typealias Distance = Int32
|
|
// CHECK: }
|