2011-09-01 02:48:32 +00:00
|
|
|
#ifndef SPROUT_DETAIL_OVERLAP_COUNT_HPP
|
|
|
|
#define SPROUT_DETAIL_OVERLAP_COUNT_HPP
|
|
|
|
|
|
|
|
#include <iterator>
|
|
|
|
#include <sprout/config.hpp>
|
2011-10-01 15:19:13 +00:00
|
|
|
#include <sprout/iterator/operation.hpp>
|
2011-09-01 02:48:32 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace detail {
|
|
|
|
template<typename Iterator>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type overlap_count_impl(
|
2011-09-01 02:48:32 +00:00
|
|
|
Iterator first,
|
|
|
|
Iterator last,
|
|
|
|
typename std::iterator_traits<Iterator>::value_type const& value,
|
|
|
|
typename std::iterator_traits<Iterator>::difference_type current = 0
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return first == last
|
|
|
|
? 0
|
|
|
|
: *first == value
|
2011-10-01 15:19:13 +00:00
|
|
|
? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, value)
|
|
|
|
: sprout::detail::overlap_count_impl(sprout::next(first), last, *first)
|
2011-09-01 02:48:32 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// overlap_count
|
|
|
|
//
|
|
|
|
template<typename Iterator>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type overlap_count(
|
2011-09-01 02:48:32 +00:00
|
|
|
Iterator first,
|
|
|
|
Iterator last
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return first == last
|
|
|
|
? 0
|
2011-10-01 15:19:13 +00:00
|
|
|
: sprout::detail::overlap_count_impl(sprout::next(first), last, *first)
|
2011-09-01 02:48:32 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Iterator, typename Predicate>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type overlap_count_impl(
|
2011-09-01 02:48:32 +00:00
|
|
|
Iterator first,
|
|
|
|
Iterator last,
|
|
|
|
Predicate pred,
|
|
|
|
typename std::iterator_traits<Iterator>::value_type const& value
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return first == last
|
|
|
|
? 0
|
|
|
|
: pred(*first, value)
|
2011-10-01 15:19:13 +00:00
|
|
|
? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, pred, value)
|
|
|
|
: sprout::detail::overlap_count_impl(sprout::next(first), last, pred, *first)
|
2011-09-01 02:48:32 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// overlap_count
|
|
|
|
//
|
|
|
|
template<typename Iterator, typename Predicate>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type overlap_count(
|
2011-09-01 02:48:32 +00:00
|
|
|
Iterator first,
|
|
|
|
Iterator last,
|
|
|
|
Predicate pred
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return first == last
|
|
|
|
? 0
|
2011-10-01 15:19:13 +00:00
|
|
|
: sprout::detail::overlap_count_impl(sprout::next(first), last, pred, *first)
|
2011-09-01 02:48:32 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_DETAIL_OVERLAP_COUNT_HPP
|