File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ module StdVector {
4
4
export *
5
5
}
6
6
7
+ module StdSpan {
8
+ header "std-span.h"
9
+ requires cplusplus
10
+ export *
11
+ }
12
+
7
13
module StdMap {
8
14
header "std-map.h"
9
15
requires cplusplus
Original file line number Diff line number Diff line change
1
+ #ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SPAN_H
2
+ #define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SPAN_H
3
+
4
+ #include < cstddef>
5
+ #include < string>
6
+ #include < span>
7
+
8
+ using Span = std::span<const int >;
9
+ using SpanOfString = std::span<const std::string>;
10
+
11
+ static int iarray[]{1 , 2 , 3 };
12
+ static std::string sarray[]{" " , " ab" , " abc" };
13
+ static Span ispan = {iarray};
14
+ static SpanOfString sspan = {sarray};
15
+
16
+ inline Span initSpan () {
17
+ const int a[]{1 , 2 , 3 };
18
+ return Span (a);
19
+ }
20
+
21
+ #endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SPAN_H
Original file line number Diff line number Diff line change
1
+ // RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xcc -std=c++20)
2
+
3
+ // FIXME swift-ci linux tests do not support std::span
4
+ // UNSUPPORTED: OS=linux-gnu
5
+
6
+ import StdlibUnittest
7
+ #if !BRIDGING_HEADER
8
+ import StdSpan
9
+ #endif
10
+ import CxxStdlib
11
+
12
+ var StdSpanTestSuite = TestSuite ( " StdSpan " )
13
+
14
+ StdSpanTestSuite . test ( " EmptySpan " ) {
15
+ let s = Span ( )
16
+ expectEqual ( s. size ( ) , 0 )
17
+ expectTrue ( s. empty ( ) )
18
+ }
19
+
20
+ StdSpanTestSuite . test ( " InitSpan " ) {
21
+ let s = initSpan ( )
22
+ expectEqual ( s. size ( ) , 3 )
23
+ expectFalse ( s. empty ( ) )
24
+ }
25
+
26
+ StdSpanTestSuite . test ( " InitStaticSpan " ) {
27
+ expectEqual ( ispan. size ( ) , 3 )
28
+ expectFalse ( ispan. empty ( ) )
29
+
30
+ expectEqual ( ispan [ 0 ] , 1 )
31
+ expectEqual ( ispan [ 1 ] , 2 )
32
+ expectEqual ( ispan [ 2 ] , 3 )
33
+ }
34
+
35
+ StdSpanTestSuite . test ( " InitStringSpan " ) {
36
+ expectEqual ( sspan. size ( ) , 3 )
37
+ expectFalse ( sspan. empty ( ) )
38
+
39
+ expectEqual ( sspan [ 0 ] , " " )
40
+ expectEqual ( sspan [ 1 ] , " ab " )
41
+ expectEqual ( sspan [ 2 ] , " abc " )
42
+ }
43
+
44
+ runAllTests ( )
You can’t perform that action at this time.
0 commit comments