Skip to content

Commit 601d6c5

Browse files
committed
[cxx-interop] Add a basic test for using stdlib iterator_traits
1 parent f1e602f commit 601d6c5

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

test/Interop/Cxx/stdlib/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
module StdIteratorTraits {
2+
header "std-iterator_traits.h"
3+
requires cplusplus
4+
}
5+
16
module StdVector {
27
header "std-vector.h"
38
requires cplusplus
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_ITERATORTRAITS_H
2+
#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_ITERATORTRAITS_H
3+
4+
#include <iterator>
5+
6+
using IteratorTraits = std::iterator_traits<int>;
7+
8+
inline IteratorTraits initIterator() { return {}; }
9+
10+
#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_ITERATOR_H
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop)
2+
//
3+
// REQUIRES: executable_test
4+
//
5+
// Enable this everywhere once we have a solution for modularizing libstdc++: rdar://87654514
6+
// REQUIRES: OS=macosx
7+
8+
import StdlibUnittest
9+
import StdIteratorTraits
10+
import std.iterator_traits
11+
12+
var StdIteratorTraitsTestSuite = TestSuite("StdIteratorTraits")
13+
14+
extension IteratorTraits : RandomAccessIteractor {
15+
public var inputIt: Int { 0 }
16+
public var numberToAdvance: Int { 1 }
17+
}
18+
19+
StdIteratorTraitsTestSuite.test("init") {
20+
let a = [12, 13, 14]
21+
let iterator = IteratorTraits()
22+
iterator.inputIt = a[0]
23+
iterator.numberToAdvance = 1
24+
expectEqual(iterator, 13)
25+
}
26+
27+
runAllTests()

0 commit comments

Comments
 (0)