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 {
|
|
|
|
template<typename Iterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
std::is_literal_type<typename std::decay<Iterator>::type>::value,
|
|
|
|
typename std::decay<Iterator>::type
|
|
|
|
>::type prev_impl(
|
|
|
|
Iterator&& it,
|
|
|
|
std::random_access_iterator_tag*
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return sprout::forward<Iterator>(it) - 1;
|
|
|
|
}
|
|
|
|
template<typename Iterator>
|
2011-10-06 06:08:59 +00:00
|
|
|
SPROUT_CONSTEXPR typename std::decay<Iterator>::type prev_impl(
|
2011-09-30 15:04:03 +00:00
|
|
|
Iterator&& it,
|
|
|
|
void*
|
|
|
|
)
|
|
|
|
{
|
2011-10-06 06:08:59 +00:00
|
|
|
using std::prev;
|
|
|
|
return prev(sprout::forward<Iterator>(it));
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Iterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
std::is_literal_type<typename std::decay<Iterator>::type>::value,
|
|
|
|
typename std::decay<Iterator>::type
|
|
|
|
>::type prev_impl(
|
|
|
|
Iterator&& it,
|
|
|
|
typename std::iterator_traits<typename std::decay<Iterator>::type>::difference_type n,
|
|
|
|
std::random_access_iterator_tag*
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return sprout::forward<Iterator>(it) - n;
|
|
|
|
}
|
|
|
|
template<typename Iterator>
|
2011-10-06 06:08:59 +00:00
|
|
|
SPROUT_CONSTEXPR typename std::decay<Iterator>::type prev_impl(
|
2011-09-30 15:04:03 +00:00
|
|
|
Iterator it,
|
|
|
|
typename std::iterator_traits<typename std::decay<Iterator>::type>::difference_type n,
|
|
|
|
void*
|
|
|
|
)
|
|
|
|
{
|
2011-10-06 06:08:59 +00:00
|
|
|
using std::prev;
|
|
|
|
return prev(sprout::forward<Iterator>(it), n);
|
2011-09-30 15:04:03 +00:00
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// prev
|
|
|
|
//
|
|
|
|
template<typename Iterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<Iterator>::type prev(Iterator&& it) {
|
2011-10-06 06:08:59 +00:00
|
|
|
typedef typename std::iterator_traits<typename std::decay<Iterator>::type>::iterator_category* category;
|
2011-09-30 15:04:03 +00:00
|
|
|
return sprout::detail::prev_impl(
|
|
|
|
sprout::forward<Iterator>(it),
|
2011-10-06 06:08:59 +00:00
|
|
|
category()
|
2011-09-30 15:04:03 +00:00
|
|
|
);
|
|
|
|
}
|
2011-10-01 15:19:13 +00:00
|
|
|
template<typename Iterator>
|
|
|
|
SPROUT_CONSTEXPR typename std::decay<Iterator>::type prev(
|
|
|
|
Iterator&& it,
|
|
|
|
typename std::iterator_traits<typename std::decay<Iterator>::type>::difference_type n
|
|
|
|
)
|
|
|
|
{
|
2011-10-06 06:08:59 +00:00
|
|
|
typedef typename std::iterator_traits<typename std::decay<Iterator>::type>::iterator_category* category;
|
2011-10-01 15:19:13 +00:00
|
|
|
return sprout::detail::prev_impl(
|
|
|
|
sprout::forward<Iterator>(it),
|
|
|
|
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
|