Files
swift-mirror/test/Interop/Cxx/stdlib/overlay/custom-sequence.swift
Egor Zhdan 40650baf7f [cxx-interop] Disable auto-conformance to CxxSequence for non-random-access collections
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.
2022-11-15 14:42:46 +00:00

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()