Files
swift-mirror/test/Interpreter/arrays.swift
Doug Gregor 86cf79a746 Add a range subscript operation for SliceInt64 that produces a slice, e.g.,
a[5..9]

will return a 4-element slice of the array a. Addresses
<rdar://problem/11329415>.


Swift SVN r1665
2012-04-27 00:07:52 +00:00

25 lines
542 B
Swift

// RUN: %swift -I %S/.. -i %s | FileCheck %s
// Create a new array
var a = new Int[10]
foreach i in 0..10 { a[i] = i }
a.replPrint()
// CHECK: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// Copy a slice to another slice
a[1..3] = a[5..7]
a.replPrint()
// CHECK: [0, 5, 6, 3, 4, 5, 6, 7, 8, 9]
// Copy a slice to another slice with overlap
a[4..8] = a[6..10]
a.replPrint()
// CHECK: [0, 5, 6, 3, 6, 7, 8, 9, 8, 9]
// Create another array and copy in a slice
var b = new Int[10]
b[3..7] = a[5..9]
b.replPrint()
// CHECK: [0, 0, 0, 7, 8, 9, 8, 0, 0, 0]