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>
|
|
|
|
#include <sprout/utility/forward.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace detail {
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename RandomAccessIterator>
|
2011-09-30 15:04:03 +00:00
|
|
|
SPROUT_CONSTEXPR typename std::enable_if<
|
2012-04-04 08:48:02 +00:00
|
|
|
std::is_literal_type<typename std::decay<RandomAccessIterator>::type>::value,
|
|
|
|
typename std::decay<RandomAccessIterator>::type
|
2011-09-30 15:04:03 +00:00
|
|
|
>::type next_impl(
|
2012-04-04 08:48:02 +00:00
|
|
|
RandomAccessIterator&& it,
|
2011-09-30 15:04:03 +00:00
|
|
|
std::random_access_iterator_tag*
|
|
|
|
)
|
|
|
|
{
|
2012-04-04 08:48:02 +00:00
|
|
|
return sprout::forward<RandomAccessIterator>(it) + 1;
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename ForwardIterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<ForwardIterator>::type next_impl(
|
|
|
|
ForwardIterator&& it,
|
2011-09-30 15:04:03 +00:00
|
|
|
void*
|
|
|
|
)
|
|
|
|
{
|
2011-10-06 06:00:08 +00:00
|
|
|
using std::next;
|
2012-04-04 08:48:02 +00:00
|
|
|
return next(sprout::forward<ForwardIterator>(it));
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
|
|
|
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename RandomAccessIterator>
|
2011-09-30 15:04:03 +00:00
|
|
|
SPROUT_CONSTEXPR typename std::enable_if<
|
2012-04-04 08:48:02 +00:00
|
|
|
std::is_literal_type<typename std::decay<RandomAccessIterator>::type>::value,
|
|
|
|
typename std::decay<RandomAccessIterator>::type
|
2011-09-30 15:04:03 +00:00
|
|
|
>::type next_impl(
|
2012-04-04 08:48:02 +00:00
|
|
|
RandomAccessIterator&& it,
|
|
|
|
typename std::iterator_traits<typename std::decay<RandomAccessIterator>::type>::difference_type n,
|
2011-09-30 15:04:03 +00:00
|
|
|
std::random_access_iterator_tag*
|
|
|
|
)
|
|
|
|
{
|
2012-04-04 08:48:02 +00:00
|
|
|
return sprout::forward<RandomAccessIterator>(it) + n;
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename ForwardIterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<ForwardIterator>::type next_impl(
|
|
|
|
ForwardIterator it,
|
|
|
|
typename std::iterator_traits<typename std::decay<ForwardIterator>::type>::difference_type n,
|
2011-09-30 15:04:03 +00:00
|
|
|
void*
|
|
|
|
)
|
|
|
|
{
|
2011-10-06 06:00:08 +00:00
|
|
|
using std::next;
|
2012-04-04 08:48:02 +00:00
|
|
|
return next(sprout::forward<ForwardIterator>(it), n);
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// next
|
|
|
|
//
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename ForwardIterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<ForwardIterator>::type next(ForwardIterator&& it) {
|
|
|
|
typedef typename std::iterator_traits<typename std::decay<ForwardIterator>::type>::iterator_category* category;
|
2011-09-30 15:04:03 +00:00
|
|
|
return sprout::detail::next_impl(
|
2012-04-04 08:48:02 +00:00
|
|
|
sprout::forward<ForwardIterator>(it),
|
2011-10-06 06:08:59 +00:00
|
|
|
category()
|
2011-09-30 15:04:03 +00:00
|
|
|
);
|
|
|
|
}
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename ForwardIterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<ForwardIterator>::type next(
|
|
|
|
ForwardIterator&& it,
|
|
|
|
typename std::iterator_traits<typename std::decay<ForwardIterator>::type>::difference_type n
|
2011-10-01 15:19:13 +00:00
|
|
|
)
|
|
|
|
{
|
2012-04-04 08:48:02 +00:00
|
|
|
typedef typename std::iterator_traits<typename std::decay<ForwardIterator>::type>::iterator_category* category;
|
2011-10-01 15:19:13 +00:00
|
|
|
return sprout::detail::next_impl(
|
2012-04-04 08:48:02 +00:00
|
|
|
sprout::forward<ForwardIterator>(it),
|
2011-10-01 15:19:13 +00:00
|
|
|
n,
|
2011-10-06 06:08:59 +00:00
|
|
|
category()
|
2011-10-01 15:19:13 +00:00
|
|
|
);
|
|
|
|
}
|
2011-09-30 15:04:03 +00:00
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_ITERATOR_NEXT_HPP
|