auto merge of #6468 : gifnksm/rust/rposition-immutable, r=brson

`position` and `rposition` belonged to `ImmutableCopyableVector`, but they don't need the value is copyable.
This commit is contained in:
bors 2013-05-14 14:05:07 -07:00
commit 043d02213e

View File

@ -2071,6 +2071,8 @@ pub trait ImmutableVector<'self, T> {
fn initn(&self, n: uint) -> &'self [T];
fn last(&self) -> &'self T;
fn last_opt(&self) -> Option<&'self T>;
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
#[cfg(stage0)]
fn each_reverse(&self, blk: &fn(&T) -> bool);
#[cfg(not(stage0))]
@ -2138,6 +2140,30 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
#[inline]
fn last_opt(&self) -> Option<&'self T> { last_opt(*self) }
/**
* Find the first index matching some predicate
*
* Apply function `f` to each element of `v`. When function `f` returns
* true then an option containing the index is returned. If `f` matches no
* elements then none is returned.
*/
#[inline]
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
position(*self, f)
}
/**
* Find the last index matching some predicate
*
* Apply function `f` to each element of `v` in reverse order. When
* function `f` returns true then an option containing the index is
* returned. If `f` matches no elements then none is returned.
*/
#[inline]
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
rposition(*self, f)
}
/// Iterates over a vector's elements in reverse.
#[inline]
#[cfg(stage0)]
@ -2230,43 +2256,17 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
}
pub trait ImmutableEqVector<T:Eq> {
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
fn position_elem(&self, t: &T) -> Option<uint>;
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
fn rposition_elem(&self, t: &T) -> Option<uint>;
}
impl<'self,T:Eq> ImmutableEqVector<T> for &'self [T] {
/**
* Find the first index matching some predicate
*
* Apply function `f` to each element of `v`. When function `f` returns
* true then an option containing the index is returned. If `f` matches no
* elements then none is returned.
*/
#[inline]
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
position(*self, f)
}
/// Find the first index containing a matching value
#[inline]
fn position_elem(&self, x: &T) -> Option<uint> {
position_elem(*self, x)
}
/**
* Find the last index matching some predicate
*
* Apply function `f` to each element of `v` in reverse order. When
* function `f` returns true then an option containing the index is
* returned. If `f` matches no elements then none is returned.
*/
#[inline]
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
rposition(*self, f)
}
/// Find the last index containing a matching value
#[inline]
fn rposition_elem(&self, t: &T) -> Option<uint> {