Commit 16444e74 authored by Jakub Pawlik's avatar Jakub Pawlik

skipWhile_i improvements

a "lazy" version of the skipWhile_i function
parent 49f2b8cc
......@@ -19,8 +19,6 @@ TEST(SkipWhileRange, ManyToMore)
auto rng = from(src);
auto dst = rng.skipWhile([](int it){return it < 0 || it > 10;});
auto vec = dst.toVector();
CheckRangeEqArray(dst, ans);
}
......
......@@ -192,19 +192,18 @@ namespace boolinq
LinqObj<Enumerator<T,std::pair<TE,int> > > skipWhile_i(std::function<bool(T,int)> predicate) const
{
auto enumerator = _enumerator;
try
{
int i = 0;
while(predicate(TE(enumerator).nextObject(),i++))
enumerator.nextObject();
}
catch(EnumeratorEndException &){}
return Enumerator<T,std::pair<TE,int> >([=](std::pair<TE,int> & pair)->T{
if( 0 == pair.second )
{
T t;
do
t = pair.first.nextObject();
while (predicate(t,pair.second++));
return t;
}
return pair.first.nextObject();
}, std::make_pair(enumerator,0));
}, std::make_pair(_enumerator,0));
}
LinqObj<Enumerator<T,std::pair<TE,int> > > skipWhile(std::function<bool(T)> predicate) const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment