@@ -1526,6 +1526,7 @@ impl<T: Copy> &[const T]: CopyableVector<T> {
1526
1526
}
1527
1527
1528
1528
trait ImmutableVector < T > {
1529
+ pure fn view ( start : uint , end : uint ) -> & [ T ] ;
1529
1530
pure fn foldr < U : Copy > ( z : U , p : fn ( T , U ) -> U ) -> U ;
1530
1531
pure fn map < U > ( f : fn ( v : & T ) -> U ) -> ~[ U ] ;
1531
1532
pure fn mapi < U > ( f : fn ( uint , v : & T ) -> U ) -> ~[ U ] ;
@@ -1544,6 +1545,10 @@ trait ImmutableEqVector<T: Eq> {
1544
1545
1545
1546
/// Extension methods for vectors
1546
1547
impl < T > & [ T ] : ImmutableVector < T > {
1548
+ /// Return a slice that points into another slice.
1549
+ pure fn view ( start : uint , end : uint ) -> & [ T ] {
1550
+ view ( self , start, end)
1551
+ }
1547
1552
/// Reduce a vector from right to left
1548
1553
#[ inline]
1549
1554
pure fn foldr < U : Copy > ( z : U , p : fn ( T , U ) -> U ) -> U { foldr ( self , z, p) }
@@ -2804,17 +2809,14 @@ mod tests {
2804
2809
assert capacity( v) == 10 u;
2805
2810
}
2806
2811
2807
- /*
2808
2812
#[ test]
2809
- #[ignore] // region inference doesn't work well enough for this yet.
2810
2813
fn test_view ( ) {
2811
2814
let v = ~[ 1 , 2 , 3 , 4 , 5 ] ;
2812
- let v = view(v, 1u, 3u);
2815
+ let v = v . view ( 1 u, 3 u) ;
2813
2816
assert ( len ( v) == 2 u) ;
2814
2817
assert ( v[ 0 ] == 2 ) ;
2815
2818
assert ( v[ 1 ] == 3 ) ;
2816
2819
}
2817
- */
2818
2820
}
2819
2821
2820
2822
// Local Variables:
0 commit comments