Skip to content

Commit

Permalink
skipWhile_i improvements
Browse files Browse the repository at this point in the history
a "lazy" version of the skipWhile_i function
  • Loading branch information
jell0nek committed Jun 30, 2013
1 parent 49f2b8c commit 16444e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 0 additions & 2 deletions boolinq/SkipWhileRangeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
21 changes: 10 additions & 11 deletions boolinq/boolinq.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 16444e7

Please sign in to comment.