2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2019-01-07 08:47:17 +00:00
|
|
|
Copyright (c) 2011-2019 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2012-11-24 04:04:02 +00:00
|
|
|
#ifndef SPROUT_RANGE_ADAPTOR_WINDOW_HPP
|
|
|
|
#define SPROUT_RANGE_ADAPTOR_WINDOW_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/type_traits/arithmetic_promote.hpp>
|
|
|
|
#include <sprout/utility/lvalue_forward.hpp>
|
2013-02-19 16:12:56 +00:00
|
|
|
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
|
2012-11-24 04:04:02 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace adaptors {
|
|
|
|
//
|
|
|
|
// window_holder
|
|
|
|
//
|
|
|
|
template<typename Difference1, typename Difference2 = void>
|
|
|
|
class window_holder {
|
|
|
|
public:
|
|
|
|
typedef typename sprout::arithmetic_promote<Difference1, Difference2>::type difference_type;
|
|
|
|
private:
|
|
|
|
difference_type to_first_;
|
|
|
|
difference_type to_last_;
|
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR window_holder(difference_type to_first, difference_type to_last)
|
|
|
|
: to_first_(to_first), to_last_(to_last)
|
|
|
|
{}
|
|
|
|
SPROUT_CONSTEXPR difference_type const& to_first() const {
|
|
|
|
return to_first_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR difference_type const& to_last() const {
|
|
|
|
return to_last_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename Difference>
|
|
|
|
class window_holder<Difference, void> {
|
|
|
|
public:
|
|
|
|
typedef Difference difference_type;
|
|
|
|
private:
|
|
|
|
difference_type to_first_;
|
|
|
|
public:
|
|
|
|
explicit SPROUT_CONSTEXPR window_holder(difference_type to_first)
|
|
|
|
: to_first_(to_first)
|
|
|
|
{}
|
|
|
|
SPROUT_CONSTEXPR difference_type const& to_first() const {
|
|
|
|
return to_first_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// window_forwarder
|
|
|
|
//
|
|
|
|
class window_forwarder {
|
|
|
|
public:
|
|
|
|
template<typename Difference1, typename Difference2>
|
|
|
|
SPROUT_CONSTEXPR sprout::adaptors::window_holder<Difference1, Difference2>
|
2013-02-19 17:23:20 +00:00
|
|
|
operator()(Difference1 to_first, Difference2 to_last) const {
|
2012-11-24 04:04:02 +00:00
|
|
|
return sprout::adaptors::window_holder<Difference1, Difference2>(to_first, to_last);
|
|
|
|
}
|
|
|
|
template<typename Difference>
|
|
|
|
SPROUT_CONSTEXPR sprout::adaptors::window_holder<Difference>
|
2013-02-19 17:23:20 +00:00
|
|
|
operator()(Difference to_first) const {
|
2012-11-24 04:04:02 +00:00
|
|
|
return sprout::adaptors::window_holder<Difference>(to_first);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// window
|
|
|
|
//
|
|
|
|
namespace {
|
2012-12-17 14:10:23 +00:00
|
|
|
SPROUT_STATIC_CONSTEXPR sprout::adaptors::window_forwarder window = {};
|
2012-11-24 04:04:02 +00:00
|
|
|
} // anonymous-namespace
|
|
|
|
|
|
|
|
//
|
|
|
|
// operator|
|
|
|
|
//
|
|
|
|
template<typename Range, typename Difference1, typename Difference2>
|
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::window_holder<Difference1, Difference2> 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.to_first(), sprout::size(sprout::lvalue_forward<Range>(lhs)))
|
|
|
|
),
|
|
|
|
sprout::next(
|
|
|
|
sprout::begin(sprout::lvalue_forward<Range>(lhs)),
|
|
|
|
NS_SSCRISK_CEL_OR_SPROUT::min<difference_type>(rhs.to_last(), sprout::size(sprout::lvalue_forward<Range>(lhs)))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
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::window_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.to_first(), sprout::size(sprout::lvalue_forward<Range>(lhs)))
|
|
|
|
),
|
|
|
|
sprout::end(sprout::lvalue_forward<Range>(lhs))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} // namespace adaptors
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_RANGE_ADAPTOR_WINDOW_HPP
|