Sprout/sprout/algorithm/count_if.hpp

22 lines
660 B
C++
Raw Normal View History

2012-04-01 13:15:09 +00:00
#ifndef SPROUT_ALGORITHM_COUNT_IF_HPP
#define SPROUT_ALGORITHM_COUNT_IF_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 25.2.9 Count
template<typename InputIterator, typename Predicate>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
2012-04-01 13:15:09 +00:00
count_if(InputIterator first, InputIterator last, Predicate pred) {
return first == last ? 0
: (pred(*first) ? 1 : 0) + sprout::count_if(sprout::next(first), last, pred)
2012-04-01 13:15:09 +00:00
;
}
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_COUNT_IF_HPP