@@ -1625,6 +1625,7 @@ impl<T: Copy> &[const T]: CopyableVector<T> {
1625
1625
}
1626
1626
1627
1627
trait ImmutableVector < T > {
1628
+ pure fn view ( start : uint , end : uint ) -> & [ T ] ;
1628
1629
pure fn foldr < U : Copy > ( z : U , p : fn ( T , U ) -> U ) -> U ;
1629
1630
pure fn iter ( f : fn ( T ) ) ;
1630
1631
pure fn iteri ( f : fn ( uint , T ) ) ;
@@ -1647,6 +1648,10 @@ trait ImmutableEqVector<T: Eq> {
1647
1648
1648
1649
/// Extension methods for vectors
1649
1650
impl < T > & [ T ] : ImmutableVector < T > {
1651
+ /// Return a slice that points into another slice.
1652
+ pure fn view ( start : uint , end : uint ) -> & [ T ] {
1653
+ view ( self , start, end)
1654
+ }
1650
1655
/// Reduce a vector from right to left
1651
1656
#[ inline]
1652
1657
pure fn foldr < U : Copy > ( z : U , p : fn ( T , U ) -> U ) -> U { foldr ( self , z, p) }
@@ -2909,17 +2914,14 @@ mod tests {
2909
2914
assert capacity( v) == 10 u;
2910
2915
}
2911
2916
2912
- /*
2913
2917
#[ test]
2914
- #[ignore] // region inference doesn't work well enough for this yet.
2915
2918
fn test_view ( ) {
2916
2919
let v = ~[ 1 , 2 , 3 , 4 , 5 ] ;
2917
- let v = view(v, 1u, 3u);
2920
+ let v = v . view ( 1 u, 3 u) ;
2918
2921
assert ( len ( v) == 2 u) ;
2919
2922
assert ( v[ 0 ] == 2 ) ;
2920
2923
assert ( v[ 1 ] == 3 ) ;
2921
2924
}
2922
- */
2923
2925
}
2924
2926
2925
2927
// Local Variables:
0 commit comments