计算元素个数(count和count_if)

count

  计算first和last之间与value相等于元素个数

template <class InputIterator,class EqualityComparable>
typename iterator_traits<_InputIterator>::difference_type
count (InputIterator first,InputIterator last,const EqualityComparable &value);

count_if

  与count相似,但是count_if是计算满足某种条件的元素的个数,满足pred(*i)为true的iterator i的个数

template<typename _InputIterator, typename _Predicate>
    typename iterator_traits<_InputIterator>::difference_type
    __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
    {
      typename iterator_traits<_InputIterator>::difference_type __n = ;
      for (; __first != __last; ++__first)
            if (__pred(__first))
                  ++__n;
      return __n;
    }
上一篇:mongodb新手扫盲


下一篇:cookielib和urllib2模块结合模拟网站登录