我只是好奇普通的人是否明白这一点。
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)
)
);
}发布于 2011-08-03 02:51:12
几点意见:
first和last,而不是使用begin和end (在通常的用法中,begin和end具体指的是限定容器中范围的迭代器)。find_if的使用似乎有点过分:是的,使用标准库算法是好的,但是如果您正在编写自己的算法,那么最好只编写一个循环,特别是如果它使代码更加清晰。考虑以下备选实施:
template <typename ForwardIterator, typename T>
ForwardIterator skip_over(ForwardIterator first, ForwardIterator last, T const& x)
{
while (first != last && *first == x)
++first;
return first;
}https://codereview.stackexchange.com/questions/3830
复制相似问题