1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

[algorithm.count_if] Reduce inner function parameter.

This commit is contained in:
Mitsuru Kariya 2013-09-03 09:32:54 +09:00
parent 5686785ea9
commit 588d6c3f1b

View file

@ -20,18 +20,18 @@ namespace sprout {
template<typename RandomAccessIterator, typename Predicate> template<typename RandomAccessIterator, typename Predicate>
inline SPROUT_CONSTEXPR typename std::iterator_traits<RandomAccessIterator>::difference_type inline SPROUT_CONSTEXPR typename std::iterator_traits<RandomAccessIterator>::difference_type
count_if_impl_ra( count_if_impl_ra(
RandomAccessIterator first, RandomAccessIterator last, Predicate pred, RandomAccessIterator first, Predicate pred,
typename std::iterator_traits<RandomAccessIterator>::difference_type pivot typename std::iterator_traits<RandomAccessIterator>::difference_type size
) )
{ {
return pivot == 0 ? (pred(*first) ? 1 : 0) return size == 1 ? (pred(*first) ? 1 : 0)
: sprout::detail::count_if_impl_ra( : sprout::detail::count_if_impl_ra(
first, sprout::next(first, pivot), pred, first, pred,
pivot / 2 size / 2
) )
+ sprout::detail::count_if_impl_ra( + sprout::detail::count_if_impl_ra(
sprout::next(first, pivot), last, pred, sprout::next(first, size / 2), pred,
(sprout::distance(first, last) - pivot) / 2 size - size / 2
) )
; ;
} }
@ -46,7 +46,7 @@ namespace sprout {
) )
{ {
return first == last ? 0 return first == last ? 0
: sprout::detail::count_if_impl_ra(first, last, pred, sprout::distance(first, last) / 2) : sprout::detail::count_if_impl_ra(first, pred, sprout::distance(first, last))
; ;
} }
@ -59,9 +59,7 @@ namespace sprout {
{ {
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type; typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;
return current.first == last ? current return current.first == last ? current
: n == 1 ? pred(*current.first) : n == 1 ? type(sprout::next(current.first), current.second + (pred(*current.first) ? 1 : 0))
? type(sprout::next(current.first), current.second + 1)
: type(sprout::next(current.first), current.second)
: sprout::detail::count_if_impl_1( : sprout::detail::count_if_impl_1(
sprout::detail::count_if_impl_1( sprout::detail::count_if_impl_1(
current, current,