mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
add range adaptors adjacent_filtered, uniqued
This commit is contained in:
parent
9aa2a7c9b2
commit
1cfec16e52
40 changed files with 571 additions and 58 deletions
118
sprout/range/adaptor/adjacent_filtered.hpp
Normal file
118
sprout/range/adaptor/adjacent_filtered.hpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_ADJACENT_FILTERED_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_ADJACENT_FILTERED_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/adjacent_filter_iterator.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
//
|
||||
// adjacent_filtered_range
|
||||
//
|
||||
template<typename Predicate, typename Range>
|
||||
class adjacent_filtered_range
|
||||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::adjacent_filter_iterator<
|
||||
Predicate,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef Predicate predicate_type;
|
||||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::adjacent_filter_iterator<
|
||||
Predicate,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
> base_type;
|
||||
typedef typename base_type::range_type range_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
adjacent_filtered_range() = default;
|
||||
adjacent_filtered_range(adjacent_filtered_range const&) = default;
|
||||
SPROUT_CONSTEXPR adjacent_filtered_range(Predicate pred, range_type& range)
|
||||
: base_type(
|
||||
iterator(pred, sprout::begin(range), sprout::end(range)),
|
||||
iterator(pred, sprout::end(range), sprout::end(range))
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// adjacent_filter_holder
|
||||
//
|
||||
template<typename Predicate>
|
||||
class adjacent_filter_holder {
|
||||
public:
|
||||
typedef Predicate predicate_type;
|
||||
private:
|
||||
Predicate pred_;
|
||||
public:
|
||||
adjacent_filter_holder() = default;
|
||||
adjacent_filter_holder(adjacent_filter_holder const&) = default;
|
||||
SPROUT_CONSTEXPR adjacent_filter_holder(Predicate pred)
|
||||
: pred_(pred)
|
||||
{}
|
||||
SPROUT_CONSTEXPR Predicate predicate() const {
|
||||
return pred_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// adjacent_filtered_forwarder
|
||||
//
|
||||
class adjacent_filtered_forwarder {
|
||||
public:
|
||||
template<typename Predicate>
|
||||
SPROUT_CONSTEXPR sprout::adaptors::adjacent_filter_holder<Predicate>
|
||||
operator()(Predicate pred) {
|
||||
return sprout::adaptors::adjacent_filter_holder<Predicate>(pred);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// adjacent_filtered
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::adjacent_filtered_forwarder adjacent_filtered = {};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::adjacent_filtered_range<
|
||||
Predicate,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::adjacent_filter_holder<Predicate> const& rhs) {
|
||||
return sprout::adaptors::adjacent_filtered_range<
|
||||
Predicate,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
rhs.predicate(),
|
||||
sprout::lvalue_forward<Range>(lhs)
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Predicate, typename Range>
|
||||
struct container_construct_traits<sprout::adaptors::adjacent_filtered_range<Predicate, Range> >
|
||||
: public sprout::container_construct_traits<typename sprout::adaptors::adjacent_filtered_range<Predicate, Range>::base_type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_ADJACENT_FILTERED_HPP
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/transform_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/value_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/clamp_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/counting_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/dft_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/value_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/filter_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/idft_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/indexed_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/joint_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/merge_iterator.hpp>
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <sprout/range/adaptor/filtered.hpp>
|
||||
#include <sprout/range/adaptor/removed.hpp>
|
||||
#include <sprout/range/adaptor/removed_if.hpp>
|
||||
#include <sprout/range/adaptor/adjacent_filtered.hpp>
|
||||
#include <sprout/range/adaptor/uniqued.hpp>
|
||||
#include <sprout/range/adaptor/reversed.hpp>
|
||||
#include <sprout/range/adaptor/merged.hpp>
|
||||
#include <sprout/range/adaptor/set_union.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/counting_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/transform_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/filter_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/filter_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/transform_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/transform_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/reverse_iterator.hpp>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/sawtooth_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/set_difference_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/set_intersection_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/set_symmetric_difference_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/set_union_iterator.hpp>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/sinusoid_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/size_enum_iterator.hpp>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <cstddef>
|
||||
#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/sized_range_default.hpp>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/square_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/step_iterator.hpp>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/transform_iterator.hpp>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/triangle_iterator.hpp>
|
||||
|
|
135
sprout/range/adaptor/uniqued.hpp
Normal file
135
sprout/range/adaptor/uniqued.hpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_UNIQUED_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_UNIQUED_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/adjacent_filter_iterator.hpp>
|
||||
#include <sprout/iterator/unique_iterator.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include <sprout/functional/equal_to.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
//
|
||||
// uniqued_range
|
||||
//
|
||||
template<typename Predicate, typename Range>
|
||||
class uniqued_range
|
||||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::adjacent_filter_iterator<
|
||||
sprout::unique_filter<Predicate>,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef Predicate predicate_type;
|
||||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::adjacent_filter_iterator<
|
||||
sprout::unique_filter<Predicate>,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
> base_type;
|
||||
typedef typename base_type::range_type range_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
uniqued_range() = default;
|
||||
uniqued_range(uniqued_range const&) = default;
|
||||
SPROUT_CONSTEXPR uniqued_range(range_type& range, Predicate pred)
|
||||
: base_type(
|
||||
iterator(typename iterator::predicate_type(pred), sprout::begin(range), sprout::end(range)),
|
||||
iterator(typename iterator::predicate_type(pred), sprout::end(range), sprout::end(range))
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// unique_holder
|
||||
//
|
||||
template<typename Predicate = sprout::equal_to<> >
|
||||
class unique_holder {
|
||||
public:
|
||||
typedef Predicate predicate_type;
|
||||
private:
|
||||
Predicate pred_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR unique_holder()
|
||||
: pred_()
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR unique_holder(Predicate pred)
|
||||
: pred_(pred)
|
||||
{}
|
||||
SPROUT_CONSTEXPR Predicate const& predicate() const {
|
||||
return pred_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// uniqued_forwarder
|
||||
//
|
||||
class uniqued_forwarder {
|
||||
public:
|
||||
template<typename Predicate>
|
||||
SPROUT_CONSTEXPR sprout::adaptors::unique_holder<Predicate>
|
||||
operator()(Predicate pred) {
|
||||
return sprout::adaptors::unique_holder<Predicate>(pred);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// uniqued
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::uniqued_forwarder uniqued = {};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::uniqued_range<
|
||||
Predicate,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::unique_holder<Predicate> const& rhs) {
|
||||
return sprout::adaptors::uniqued_range<
|
||||
Predicate,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs),
|
||||
rhs.predicate()
|
||||
);
|
||||
}
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::uniqued_range<
|
||||
sprout::equal_to<>,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::uniqued_forwarder const& rhs) {
|
||||
return sprout::adaptors::uniqued_range<
|
||||
sprout::equal_to<>,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs),
|
||||
sprout::equal_to<>()
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Predicate, typename Range>
|
||||
struct container_construct_traits<sprout::adaptors::uniqued_range<Predicate, Range> >
|
||||
: public sprout::container_construct_traits<typename sprout::adaptors::uniqued_range<Predicate, Range>::base_type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_UNIQUED_HPP
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/valued_iterator.hpp>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue