2012-11-24 04:04:02 +00:00
|
|
|
#ifndef SPROUT_RANGE_ADAPTOR_DROPPED_HPP
|
|
|
|
#define SPROUT_RANGE_ADAPTOR_DROPPED_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
|
|
|
#include <sprout/iterator/next.hpp>
|
2012-11-30 18:00:46 +00:00
|
|
|
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
2012-11-24 04:04:02 +00:00
|
|
|
#include <sprout/type_traits/lvalue_reference.hpp>
|
|
|
|
#include <sprout/utility/lvalue_forward.hpp>
|
|
|
|
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace adaptors {
|
|
|
|
//
|
|
|
|
// drop_holder
|
|
|
|
//
|
|
|
|
template<typename Difference>
|
|
|
|
class drop_holder {
|
|
|
|
public:
|
|
|
|
typedef Difference difference_type;
|
|
|
|
private:
|
|
|
|
difference_type distance_;
|
|
|
|
public:
|
|
|
|
explicit SPROUT_CONSTEXPR drop_holder(difference_type distance)
|
|
|
|
: distance_(distance)
|
|
|
|
{}
|
|
|
|
SPROUT_CONSTEXPR difference_type const& distance() const {
|
|
|
|
return distance_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// dropped_forwarder
|
|
|
|
//
|
|
|
|
class dropped_forwarder {
|
|
|
|
public:
|
|
|
|
template<typename Difference>
|
|
|
|
SPROUT_CONSTEXPR sprout::adaptors::drop_holder<Difference>
|
|
|
|
operator()(Difference distance) {
|
|
|
|
return sprout::adaptors::drop_holder<Difference>(distance);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// dropped
|
|
|
|
//
|
|
|
|
namespace {
|
2012-12-17 14:10:23 +00:00
|
|
|
SPROUT_STATIC_CONSTEXPR sprout::adaptors::dropped_forwarder dropped = {};
|
2012-11-24 04:04:02 +00:00
|
|
|
} // anonymous-namespace
|
|
|
|
|
|
|
|
//
|
|
|
|
// operator|
|
|
|
|
//
|
|
|
|
template<typename Range, typename Difference>
|
2012-11-30 18:00:46 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
2012-11-24 04:04:02 +00:00
|
|
|
>
|
|
|
|
operator|(Range&& lhs, sprout::adaptors::drop_holder<Difference> const& rhs) {
|
|
|
|
typedef typename sprout::container_traits<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
|
|
|
>::difference_type difference_type;
|
2012-11-30 18:00:46 +00:00
|
|
|
return sprout::adaptors::detail::adapted_range_default<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
2012-11-24 04:04:02 +00:00
|
|
|
>(
|
|
|
|
sprout::next(
|
|
|
|
sprout::begin(sprout::lvalue_forward<Range>(lhs)),
|
|
|
|
NS_SSCRISK_CEL_OR_SPROUT::min<difference_type>(rhs.distance(), sprout::size(sprout::lvalue_forward<Range>(lhs)))
|
|
|
|
),
|
|
|
|
sprout::end(sprout::lvalue_forward<Range>(lhs))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} // namespace adaptors
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_RANGE_ADAPTOR_DROPPED_HPP
|