Skip to content

Commit

Permalink
skipWhile improvements
Browse files Browse the repository at this point in the history
an improvement of the skipWhile function
  • Loading branch information
jell0nek committed Jun 27, 2013
1 parent 79b91c2 commit 0b63d46
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions boolinq/boolinq.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,17 @@ namespace boolinq

LinqObj<Enumerator<T,std::pair<TE,int> > > skipWhile(std::function<bool(T)> predicate) const
{
auto enumerator = _enumerator;

try
{
while(predicate(TE(enumerator).nextObject()));
}
catch(EnumeratorEndException &){}

return Enumerator<T,std::pair<TE,int> >([=](std::pair<TE,int> & pair)->T{
T object = pair.first.nextObject();;
if( 0 == pair.second++ )
while (predicate(object))
object = pair.first.nextObject();
return object;
}, std::make_pair(_enumerator,0));
return pair.first.nextObject();
}, std::make_pair(enumerator,0));
}

template<typename TRet>
Expand Down

0 comments on commit 0b63d46

Please sign in to comment.