2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2018-12-30 08:25:21 +00:00
|
|
|
Copyright (c) 2011-2018 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)
|
|
|
|
=============================================================================*/
|
2013-01-03 08:01:50 +00:00
|
|
|
#ifndef TESTSPR_RANGE_HPP
|
|
|
|
#define TESTSPR_RANGE_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/pit.hpp>
|
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
|
|
|
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
|
|
|
#include <sprout/range/algorithm/copy.hpp>
|
|
|
|
#include <sprout/type_traits/lvalue_reference.hpp>
|
|
|
|
#include <sprout/utility/forward.hpp>
|
|
|
|
#include <sprout/utility/lvalue_forward.hpp>
|
|
|
|
#include <testspr/iterator.hpp>
|
|
|
|
|
|
|
|
namespace testspr {
|
|
|
|
namespace range {
|
|
|
|
//
|
|
|
|
// reducted_range
|
|
|
|
//
|
2015-05-11 01:34:12 +00:00
|
|
|
template<typename Range, typename Category = typename testspr::reduce_iterator<typename sprout::container_traits<Range>::iterator>::iterator_category>
|
2013-01-03 08:01:50 +00:00
|
|
|
class reducted_range
|
|
|
|
: public sprout::adaptors::detail::adapted_range_default<
|
|
|
|
Range,
|
2015-05-11 01:34:12 +00:00
|
|
|
testspr::reduce_iterator<typename sprout::container_traits<Range>::iterator, Category>
|
2013-01-03 08:01:50 +00:00
|
|
|
>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef sprout::adaptors::detail::adapted_range_default<
|
|
|
|
Range,
|
2015-05-11 01:34:12 +00:00
|
|
|
testspr::reduce_iterator<typename sprout::container_traits<Range>::iterator, Category>
|
2013-01-03 08:01:50 +00:00
|
|
|
> base_type;
|
|
|
|
typedef typename base_type::range_type range_type;
|
|
|
|
typedef typename base_type::iterator iterator;
|
|
|
|
public:
|
2014-01-13 15:18:06 +00:00
|
|
|
SPROUT_CONSTEXPR reducted_range() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL
|
2013-01-03 08:01:50 +00:00
|
|
|
reducted_range(reducted_range const&) = default;
|
|
|
|
explicit SPROUT_CONSTEXPR reducted_range(range_type& range)
|
|
|
|
: base_type(
|
|
|
|
iterator(sprout::end(range)),
|
|
|
|
iterator(sprout::begin(range))
|
|
|
|
)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2015-05-11 01:34:12 +00:00
|
|
|
// make_reduce_range
|
2013-01-03 08:01:50 +00:00
|
|
|
//
|
|
|
|
template<typename Range>
|
|
|
|
inline SPROUT_CONSTEXPR testspr::range::reducted_range<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
|
|
|
>
|
2015-05-11 01:34:12 +00:00
|
|
|
make_reduce_range(Range&& rng) {
|
2013-01-03 08:01:50 +00:00
|
|
|
return testspr::range::reducted_range<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
|
|
|
>(
|
|
|
|
sprout::lvalue_forward<Range>(rng)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
template<typename Category, typename Range>
|
|
|
|
inline SPROUT_CONSTEXPR testspr::range::reducted_range<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
|
|
|
Category
|
|
|
|
>
|
2015-05-11 01:34:12 +00:00
|
|
|
make_reduce_range(Range&& rng) {
|
2013-01-03 08:01:50 +00:00
|
|
|
return testspr::range::reducted_range<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
|
|
|
Category
|
|
|
|
>(
|
|
|
|
sprout::lvalue_forward<Range>(rng)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2015-05-11 01:34:12 +00:00
|
|
|
// reduce_input
|
|
|
|
// reduce_forward
|
|
|
|
// reduce_bidirectional
|
|
|
|
// reduce_random_access
|
2013-01-03 08:01:50 +00:00
|
|
|
//
|
|
|
|
template<typename Range>
|
|
|
|
inline SPROUT_CONSTEXPR testspr::range::reducted_range<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
|
|
|
std::input_iterator_tag
|
|
|
|
>
|
2015-05-11 01:34:12 +00:00
|
|
|
reduce_input(Range&& rng) {
|
|
|
|
return testspr::range::make_reduce_range<std::input_iterator_tag>(SPROUT_FORWARD(Range, rng));
|
2013-01-03 08:01:50 +00:00
|
|
|
}
|
|
|
|
template<typename Range>
|
|
|
|
inline SPROUT_CONSTEXPR testspr::range::reducted_range<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
|
|
|
std::forward_iterator_tag
|
|
|
|
>
|
2015-05-11 01:34:12 +00:00
|
|
|
reduce_forward(Range&& rng) {
|
|
|
|
return testspr::range::make_reduce_range<std::forward_iterator_tag>(SPROUT_FORWARD(Range, rng));
|
2013-01-03 08:01:50 +00:00
|
|
|
}
|
|
|
|
template<typename Range>
|
|
|
|
inline SPROUT_CONSTEXPR testspr::range::reducted_range<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
|
|
|
std::bidirectional_iterator_tag
|
|
|
|
>
|
2015-05-11 01:34:12 +00:00
|
|
|
reduce_bidirectional(Range&& rng) {
|
|
|
|
return testspr::range::make_reduce_range<std::bidirectional_iterator_tag>(SPROUT_FORWARD(Range, rng));
|
2013-01-03 08:01:50 +00:00
|
|
|
}
|
|
|
|
template<typename Range>
|
|
|
|
inline SPROUT_CONSTEXPR testspr::range::reducted_range<
|
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
|
|
|
std::random_access_iterator_tag
|
|
|
|
>
|
2015-05-11 01:34:12 +00:00
|
|
|
reduce_random_access(Range&& rng) {
|
|
|
|
return testspr::range::make_reduce_range<std::random_access_iterator_tag>(SPROUT_FORWARD(Range, rng));
|
2013-01-03 08:01:50 +00:00
|
|
|
}
|
|
|
|
} // namespace range
|
|
|
|
} // namespace testspr
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
//
|
|
|
|
// container_construct_traits
|
|
|
|
//
|
|
|
|
template<typename Range, typename Category>
|
|
|
|
struct container_construct_traits<testspr::range::reducted_range<Range, Category> >
|
|
|
|
: public sprout::container_construct_traits<typename testspr::range::reducted_range<Range, Category>::base_type>
|
|
|
|
{};
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef TESTSPR_RANGE_HPP
|