# Skip_over() algorithm

I'm just curious if this is clear to the average person.

template<typename IteratorType>
inline IteratorType skip_over(
IteratorType begin,
IteratorType end,
typename std::iterator_traits<IteratorType>::value_type skippedCharacter)
{
typedef typename std::iterator_traits<IteratorType>::value_type value_type;
return std::find_if(begin, end,
std::not1(
std::bind2nd(std::equal_to<value_type>(), skippedCharacter)
)
);
}

• It took me a while to work out what it did (comments would not go amiss). Aug 3 '11 at 3:56

• Algorithms typically use the names first and last for the iterators they take, not begin and end (in common usage, begin and end refer specifically to the iterators that delimit a range in a container).

• The use of find_if seems a bit excessive: yes, it is good to use the Standard Library algorithms, but if you are writing your own algorithm, you may as well just write a loop, especially if it makes the code much clearer.

• With respect to template parameter naming, it is helpful if you say what category of iterator is required; this helps to document the algorithm.

Consider the following, alternative implementation:

template <typename ForwardIterator, typename T>
ForwardIterator skip_over(ForwardIterator first, ForwardIterator last, T const& x)
{
while (first != last && *first == x)
++first;

return first;
}

• I'm not sure why, but I think I'd prefer for (;first!=last && *first==x; ++first); return first; (with the empty semicolon on its own line, of course). Aug 4 '11 at 22:10