2011-09-30 15:04:03 +00:00
|
|
|
#ifndef SPROUT_ITERATOR_PREV_HPP
|
|
|
|
#define SPROUT_ITERATOR_PREV_HPP
|
|
|
|
|
|
|
|
#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 prev_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 BidirectionalIterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<BidirectionalIterator>::type prev_impl(
|
|
|
|
BidirectionalIterator&& it,
|
2011-09-30 15:04:03 +00:00
|
|
|
void*
|
|
|
|
)
|
|
|
|
{
|
2011-10-06 06:08:59 +00:00
|
|
|
using std::prev;
|
2012-04-04 08:48:02 +00:00
|
|
|
return prev(sprout::forward<BidirectionalIterator>(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 prev_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 BidirectionalIterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<BidirectionalIterator>::type prev_impl(
|
|
|
|
BidirectionalIterator it,
|
|
|
|
typename std::iterator_traits<typename std::decay<BidirectionalIterator>::type>::difference_type n,
|
2011-09-30 15:04:03 +00:00
|
|
|
void*
|
|
|
|
)
|
|
|
|
{
|
2011-10-06 06:08:59 +00:00
|
|
|
using std::prev;
|
2012-04-04 08:48:02 +00:00
|
|
|
return prev(sprout::forward<BidirectionalIterator>(it), n);
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// prev
|
|
|
|
//
|
2012-04-04 08:48:02 +00:00
|
|
|
template<typename BidirectionalIterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<BidirectionalIterator>::type prev(BidirectionalIterator&& it) {
|
|
|
|
typedef typename std::iterator_traits<typename std::decay<BidirectionalIterator>::type>::iterator_category* category;
|
2011-09-30 15:04:03 +00:00
|
|
|
return sprout::detail::prev_impl(
|
2012-04-04 08:48:02 +00:00
|
|
|
sprout::forward<BidirectionalIterator>(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 BidirectionalIterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<BidirectionalIterator>::type prev(
|
|
|
|
BidirectionalIterator&& it,
|
|
|
|
typename std::iterator_traits<typename std::decay<BidirectionalIterator>::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<BidirectionalIterator>::type>::iterator_category* category;
|
2011-10-01 15:19:13 +00:00
|
|
|
return sprout::detail::prev_impl(
|
2012-04-04 08:48:02 +00:00
|
|
|
sprout::forward<BidirectionalIterator>(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_PREV_HPP
|