2012-04-01 13:15:09 +00:00
|
|
|
#ifndef SPROUT_ITERATOR_DISTANCE_HPP
|
|
|
|
#define SPROUT_ITERATOR_DISTANCE_HPP
|
|
|
|
|
|
|
|
#include <iterator>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/iterator/next.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace detail {
|
|
|
|
// Copyright (C) 2011 RiSK (sscrisk)
|
|
|
|
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename InputIterator>
|
2012-07-15 07:04:05 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
2012-04-04 08:48:02 +00:00
|
|
|
distance(InputIterator first, InputIterator last) {
|
2012-04-01 13:15:09 +00:00
|
|
|
return first == last ? 0
|
|
|
|
: 1 + sprout::detail::distance(sprout::next(first), last)
|
|
|
|
;
|
|
|
|
}
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename InputIterator>
|
2012-07-15 07:04:05 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
2012-04-04 08:48:02 +00:00
|
|
|
distance_impl(InputIterator first, InputIterator last) {
|
2012-04-01 13:15:09 +00:00
|
|
|
using sprout::detail::distance;
|
|
|
|
return distance(first, last);
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// distance
|
|
|
|
//
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename InputIterator>
|
2012-07-15 07:04:05 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
2012-04-04 08:48:02 +00:00
|
|
|
distance(InputIterator first, InputIterator last) {
|
2012-04-01 13:15:09 +00:00
|
|
|
return sprout::detail::distance_impl(first, last);
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_ITERATOR_DISTANCE_HPP
|