mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Iterating over a `CxxSequence` that is not a `CxxRandomAccessCollection` triggers a copy of the C++ collection. Let's disable the automatic conformances until we find a more efficient solution. This means that for now developers won't be able to iterate over a `std::set` or `std::list` with a Swift for-in loop. I will submit a separate patch with an alternative solution for such types. C++ random access collections, such as `std::vector` or `std::string`, are not affected.
36 lines
787 B
Swift
36 lines
787 B
Swift
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
|
|
//
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: OS=macosx || OS=linux-gnu
|
|
|
|
// REQUIRES: rdar102364960
|
|
|
|
import StdlibUnittest
|
|
import CustomSequence
|
|
|
|
var CxxSequenceTestSuite = TestSuite("CxxSequence")
|
|
|
|
CxxSequenceTestSuite.test("SimpleSequence as Swift.Sequence") {
|
|
let seq = SimpleSequence()
|
|
let contains = seq.contains(where: { $0 == 3 })
|
|
expectTrue(contains)
|
|
|
|
var items: [Int32] = []
|
|
for item in seq {
|
|
items.append(item)
|
|
}
|
|
expectEqual([1, 2, 3, 4] as [Int32], items)
|
|
}
|
|
|
|
CxxSequenceTestSuite.test("SimpleEmptySequence as Swift.Sequence") {
|
|
let seq = SimpleEmptySequence()
|
|
|
|
var iterated = false
|
|
for _ in seq {
|
|
iterated = true
|
|
}
|
|
expectFalse(iterated)
|
|
}
|
|
|
|
runAllTests()
|