2011-09-30 15:04:03 +00:00
|
|
|
#ifndef SPROUT_ITERATOR_NEXT_HPP
|
|
|
|
#define SPROUT_ITERATOR_NEXT_HPP
|
2011-10-26 06:57:31 +00:00
|
|
|
|
2011-09-30 15:04:03 +00:00
|
|
|
#include <iterator>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
2012-09-29 08:10:46 +00:00
|
|
|
#include <sprout/adl/not_found.hpp>
|
|
|
|
|
|
|
|
namespace sprout_adl {
|
2012-09-29 14:39:00 +00:00
|
|
|
sprout::not_found_via_adl iterator_next(...);
|
2012-09-29 08:10:46 +00:00
|
|
|
} // namespace sprout_adl
|
2011-09-30 15:04:03 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
2012-09-26 07:31:11 +00:00
|
|
|
namespace iterator_detail {
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename RandomAccessIterator>
|
2012-07-15 07:04:05 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-26 07:31:11 +00:00
|
|
|
std::is_literal_type<RandomAccessIterator>::value,
|
|
|
|
RandomAccessIterator
|
2012-10-05 15:58:56 +00:00
|
|
|
>::type
|
|
|
|
next_impl(RandomAccessIterator const& it, std::random_access_iterator_tag*) {
|
2012-09-26 07:31:11 +00:00
|
|
|
return it + 1;
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename ForwardIterator>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator
|
|
|
|
next_impl(ForwardIterator const& it, void*) {
|
2012-09-26 07:31:11 +00:00
|
|
|
return std::next(it);
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
|
|
|
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename RandomAccessIterator>
|
2012-07-15 07:04:05 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-26 07:31:11 +00:00
|
|
|
std::is_literal_type<RandomAccessIterator>::value,
|
|
|
|
RandomAccessIterator
|
2012-10-05 15:58:56 +00:00
|
|
|
>::type
|
|
|
|
next_impl(
|
|
|
|
RandomAccessIterator const& it, typename std::iterator_traits<RandomAccessIterator>::difference_type n,
|
2011-09-30 15:04:03 +00:00
|
|
|
std::random_access_iterator_tag*
|
|
|
|
)
|
|
|
|
{
|
2012-09-26 07:31:11 +00:00
|
|
|
return it + n;
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename ForwardIterator>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator
|
|
|
|
next_impl(
|
|
|
|
ForwardIterator const& it, typename std::iterator_traits<ForwardIterator>::difference_type n,
|
2011-09-30 15:04:03 +00:00
|
|
|
void*
|
|
|
|
)
|
|
|
|
{
|
2012-09-26 07:31:11 +00:00
|
|
|
return std::next(it, n);
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
2012-09-26 07:31:11 +00:00
|
|
|
|
|
|
|
template<typename ForwardIterator>
|
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator
|
|
|
|
iterator_next(ForwardIterator const& it) {
|
|
|
|
typedef typename std::iterator_traits<ForwardIterator>::iterator_category* category;
|
|
|
|
return sprout::iterator_detail::next_impl(it, category());
|
|
|
|
}
|
|
|
|
template<typename ForwardIterator>
|
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator
|
|
|
|
iterator_next(ForwardIterator const& it, typename std::iterator_traits<ForwardIterator>::difference_type n) {
|
|
|
|
typedef typename std::iterator_traits<ForwardIterator>::iterator_category* category;
|
|
|
|
return sprout::iterator_detail::next_impl(it, n, category());
|
|
|
|
}
|
|
|
|
} // namespace iterator_detail
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
namespace sprout_iterator_detail {
|
|
|
|
template<typename ForwardIterator>
|
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator
|
|
|
|
next(ForwardIterator const& it) {
|
|
|
|
using sprout::iterator_detail::iterator_next;
|
2012-09-29 08:10:46 +00:00
|
|
|
using sprout_adl::iterator_next;
|
2012-09-26 07:31:11 +00:00
|
|
|
return iterator_next(it);
|
|
|
|
}
|
|
|
|
template<typename ForwardIterator>
|
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator
|
|
|
|
next(ForwardIterator const& it, typename std::iterator_traits<ForwardIterator>::difference_type n) {
|
|
|
|
using sprout::iterator_detail::iterator_next;
|
2012-09-29 08:10:46 +00:00
|
|
|
using sprout_adl::iterator_next;
|
2012-09-26 07:31:11 +00:00
|
|
|
return iterator_next(it, n);
|
|
|
|
}
|
|
|
|
} // namespace sprout_iterator_detail
|
|
|
|
|
|
|
|
namespace sprout {
|
2011-09-30 15:04:03 +00:00
|
|
|
//
|
|
|
|
// next
|
|
|
|
//
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename ForwardIterator>
|
2012-09-26 07:31:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator
|
|
|
|
next(ForwardIterator const& it) {
|
|
|
|
return sprout_iterator_detail::next(it);
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename ForwardIterator>
|
2012-09-26 07:31:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator
|
|
|
|
next(ForwardIterator const& it, typename std::iterator_traits<ForwardIterator>::difference_type n) {
|
|
|
|
return sprout_iterator_detail::next(it, n);
|
2011-10-01 15:19:13 +00:00
|
|
|
}
|
2011-09-30 15:04:03 +00:00
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_ITERATOR_NEXT_HPP
|