mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +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
|
@ -1,11 +1,13 @@
|
|||
#ifndef SPROUT_ALGORITHM_FIXED_UNIQUE_COPY_HPP
|
||||
#define SPROUT_ALGORITHM_FIXED_UNIQUE_COPY_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/unique_iterator.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/detail/container_complate.hpp>
|
||||
|
@ -48,6 +50,41 @@ namespace sprout {
|
|||
: sprout::detail::container_complate(result, args..., head)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename Result>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::is_fixed_container<Result>::value,
|
||||
typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
>::type
|
||||
unique_copy(InputIterator first, InputIterator last, Result const& result) {
|
||||
return first != last
|
||||
? sprout::fixed::detail::unique_copy_impl(sprout::next(first), last, result, sprout::size(result), *first)
|
||||
: sprout::detail::container_complate(result)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename Result>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
unique_copy_dyn(
|
||||
InputIterator first, InputIterator last, Result const& result,
|
||||
std::forward_iterator_tag*
|
||||
)
|
||||
{
|
||||
return sprout::remake<Result>(
|
||||
result, sprout::size(result),
|
||||
sprout::make_unique_iterator(first, last),
|
||||
sprout::make_unique_iterator(last, last)
|
||||
);
|
||||
}
|
||||
template<typename InputIterator, typename Result>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!sprout::is_fixed_container<Result>::value,
|
||||
typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
>::type
|
||||
unique_copy(InputIterator first, InputIterator last, Result const& result) {
|
||||
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
||||
return sprout::fixed::detail::unique_copy_dyn(first, last, result, category());
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// unique_copy
|
||||
|
@ -55,10 +92,7 @@ namespace sprout {
|
|||
template<typename InputIterator, typename Result>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
unique_copy(InputIterator first, InputIterator last, Result const& result) {
|
||||
return first != last
|
||||
? sprout::fixed::detail::unique_copy_impl(sprout::next(first), last, result, sprout::size(result), *first)
|
||||
: sprout::detail::container_complate(result)
|
||||
;
|
||||
return sprout::fixed::detail::unique_copy(first, last, result);
|
||||
}
|
||||
|
||||
template<typename Result, typename InputIterator>
|
||||
|
@ -103,6 +137,41 @@ namespace sprout {
|
|||
: sprout::detail::container_complate(result, args..., head)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename Result, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::is_fixed_container<Result>::value,
|
||||
typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
>::type
|
||||
unique_copy(InputIterator first, InputIterator last, Result const& result, BinaryPredicate pred) {
|
||||
return first != last
|
||||
? sprout::fixed::detail::unique_copy_impl(sprout::next(first), last, result, pred, sprout::size(result), *first)
|
||||
: sprout::detail::container_complate(result)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename Result, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
unique_copy_dyn(
|
||||
InputIterator first, InputIterator last, Result const& result, BinaryPredicate pred,
|
||||
std::forward_iterator_tag*
|
||||
)
|
||||
{
|
||||
return sprout::remake<Result>(
|
||||
result, sprout::size(result),
|
||||
sprout::make_unique_iterator(pred, first, last),
|
||||
sprout::make_unique_iterator(pred, last, last)
|
||||
);
|
||||
}
|
||||
template<typename InputIterator, typename Result, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!sprout::is_fixed_container<Result>::value,
|
||||
typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
>::type
|
||||
unique_copy(InputIterator first, InputIterator last, Result const& result, BinaryPredicate pred) {
|
||||
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
||||
return sprout::fixed::detail::unique_copy_dyn(first, last, result, pred, category());
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// unique_copy
|
||||
|
@ -110,10 +179,7 @@ namespace sprout {
|
|||
template<typename InputIterator, typename Result, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
unique_copy(InputIterator first, InputIterator last, Result const& result, BinaryPredicate pred) {
|
||||
return first != last
|
||||
? sprout::fixed::detail::unique_copy_impl(sprout::next(first), last, result, pred, sprout::size(result), *first)
|
||||
: sprout::detail::container_complate(result)
|
||||
;
|
||||
return sprout::fixed::detail::unique_copy(first, last, result, pred);
|
||||
}
|
||||
|
||||
template<typename Result, typename InputIterator, typename BinaryPredicate>
|
||||
|
|
|
@ -9,17 +9,19 @@
|
|||
#include <sprout/iterator/filter_iterator.hpp>
|
||||
#include <sprout/iterator/remove_iterator.hpp>
|
||||
#include <sprout/iterator/remove_if_iterator.hpp>
|
||||
#include <sprout/iterator/adjacent_filter_iterator.hpp>
|
||||
#include <sprout/iterator/unique_iterator.hpp>
|
||||
#include <sprout/iterator/merge_iterator.hpp>
|
||||
#include <sprout/iterator/set_union_iterator.hpp>
|
||||
#include <sprout/iterator/set_intersection_iterator.hpp>
|
||||
#include <sprout/iterator/set_difference_iterator.hpp>
|
||||
#include <sprout/iterator/set_symmetric_difference_iterator.hpp>
|
||||
#include <sprout/iterator/while_iterator.hpp>
|
||||
#include <sprout/iterator/step_iterator.hpp>
|
||||
#include <sprout/iterator/indexed_iterator.hpp>
|
||||
#include <sprout/iterator/valued_iterator.hpp>
|
||||
#include <sprout/iterator/joint_iterator.hpp>
|
||||
#include <sprout/iterator/alternate_iterator.hpp>
|
||||
#include <sprout/iterator/merge_iterator.hpp>
|
||||
#include <sprout/iterator/set_union_iterator.hpp>
|
||||
#include <sprout/iterator/set_intersection_iterator.hpp>
|
||||
#include <sprout/iterator/set_difference_iterator.hpp>
|
||||
#include <sprout/iterator/set_symmetric_difference_iterator.hpp>
|
||||
#include <sprout/iterator/size_enum_iterator.hpp>
|
||||
#include <sprout/iterator/bytes_iterator.hpp>
|
||||
#include <sprout/iterator/remake_iterator.hpp>
|
||||
|
|
177
sprout/iterator/adjacent_filter_iterator.hpp
Normal file
177
sprout/iterator/adjacent_filter_iterator.hpp
Normal file
|
@ -0,0 +1,177 @@
|
|||
#ifndef SPROUT_ITERATOR_ADJACENT_FILTER_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_ADJACENT_FILTER_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/algorithm/adjacent_find.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// adjacent_filter_iterator
|
||||
//
|
||||
template<typename Predicate, typename Iterator>
|
||||
class adjacent_filter_iterator
|
||||
: public std::iterator<
|
||||
typename sprout::min_iterator_category<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::forward_iterator_tag
|
||||
>::type,
|
||||
typename std::iterator_traits<Iterator>::value_type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
typename std::iterator_traits<Iterator>::pointer,
|
||||
typename std::iterator_traits<Iterator>::reference
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef Predicate predicate_type;
|
||||
typedef Iterator iterator_type;
|
||||
typedef typename sprout::min_iterator_category<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::forward_iterator_tag
|
||||
>::type iterator_category;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
|
||||
typedef typename std::iterator_traits<Iterator>::pointer pointer;
|
||||
typedef typename std::iterator_traits<Iterator>::reference reference;
|
||||
private:
|
||||
struct private_constructor_tag {};
|
||||
private:
|
||||
static SPROUT_CONSTEXPR iterator_type find_next(iterator_type first, iterator_type last, Predicate pred) {
|
||||
return sprout::adjacent_find(first, last, pred);
|
||||
}
|
||||
static SPROUT_CONSTEXPR iterator_type checked_next(iterator_type found, iterator_type last) {
|
||||
return found == last ? last
|
||||
: sprout::next(found)
|
||||
;
|
||||
}
|
||||
protected:
|
||||
iterator_type current;
|
||||
iterator_type last;
|
||||
Predicate pred;
|
||||
private:
|
||||
void satisfy_predicate() {
|
||||
current = sprout::adjacent_find(current, last, pred);
|
||||
}
|
||||
SPROUT_CONSTEXPR adjacent_filter_iterator(Predicate pred, iterator_type it, iterator_type last, private_constructor_tag)
|
||||
: current(it)
|
||||
, last(last)
|
||||
, pred(pred)
|
||||
{}
|
||||
public:
|
||||
adjacent_filter_iterator() = default;
|
||||
adjacent_filter_iterator(adjacent_filter_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR adjacent_filter_iterator(Predicate pred, iterator_type it, iterator_type last = iterator_type())
|
||||
: current(find_next(it, last, pred))
|
||||
, last(last)
|
||||
, pred(pred)
|
||||
{}
|
||||
template<typename U>
|
||||
SPROUT_CONSTEXPR adjacent_filter_iterator(adjacent_filter_iterator<Predicate, U> const& it)
|
||||
: current(it.current)
|
||||
, last(it.last)
|
||||
, pred(it.pred)
|
||||
{}
|
||||
template<typename U>
|
||||
adjacent_filter_iterator& operator=(adjacent_filter_iterator<Predicate, U> const& it) {
|
||||
adjacent_filter_iterator temp(it);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type base() const {
|
||||
return current;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type end() const {
|
||||
return last;
|
||||
}
|
||||
SPROUT_CONSTEXPR Predicate predicate() const {
|
||||
return pred;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return *current;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &*current;
|
||||
}
|
||||
|
||||
adjacent_filter_iterator& operator++() {
|
||||
satisfy_predicate();
|
||||
if (current != last) {
|
||||
++current;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
adjacent_filter_iterator operator++(int) {
|
||||
adjacent_filter_iterator result(*this);
|
||||
satisfy_predicate();
|
||||
if (current != last) {
|
||||
++current;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
SPROUT_CONSTEXPR adjacent_filter_iterator next() const {
|
||||
return adjacent_filter_iterator(pred, checked_next(find_next(current, last, pred), last), last, private_constructor_tag());
|
||||
}
|
||||
void swap(adjacent_filter_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(last, other.last))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(pred, other.pred))
|
||||
)
|
||||
{
|
||||
sprout::swap(current, other.current);
|
||||
sprout::swap(last, other.last);
|
||||
sprout::swap(pred, other.pred);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Predicate, typename Iterator1, typename Iterator2>
|
||||
inline SPROUT_CONSTEXPR bool operator==(
|
||||
sprout::adjacent_filter_iterator<Predicate, Iterator1> const& lhs,
|
||||
sprout::adjacent_filter_iterator<Predicate, Iterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() == rhs.base();
|
||||
}
|
||||
template<typename Predicate, typename Iterator1, typename Iterator2>
|
||||
inline SPROUT_CONSTEXPR bool operator!=(
|
||||
sprout::adjacent_filter_iterator<Predicate, Iterator1> const& lhs,
|
||||
sprout::adjacent_filter_iterator<Predicate, Iterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// make_adjacent_filter_iterator
|
||||
//
|
||||
template<typename Predicate, typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::adjacent_filter_iterator<Predicate, Iterator>
|
||||
make_adjacent_filter_iterator(Predicate pred, Iterator it, Iterator last = Iterator()) {
|
||||
return sprout::adjacent_filter_iterator<Predicate, Iterator>(pred, it, last);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename Predicate, typename Iterator>
|
||||
inline void
|
||||
swap(sprout::adjacent_filter_iterator<Predicate, Iterator>& lhs, sprout::adjacent_filter_iterator<Predicate, Iterator>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_next
|
||||
//
|
||||
template<typename Predicate, typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::adjacent_filter_iterator<Predicate, Iterator>
|
||||
iterator_next(sprout::adjacent_filter_iterator<Predicate, Iterator> const& it) {
|
||||
return it.next();
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // SPROUT_ITERATOR_ADJACENT_FILTER_ITERATOR_HPP
|
|
@ -2,11 +2,10 @@
|
|||
#define SPROUT_ITERATOR_FILTER_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/prev.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/algorithm/find_if.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
|
||||
|
@ -17,10 +16,9 @@ namespace sprout {
|
|||
template<typename Predicate, typename Iterator>
|
||||
class filter_iterator
|
||||
: public std::iterator<
|
||||
typename std::conditional<
|
||||
std::is_convertible<typename std::iterator_traits<Iterator>::iterator_category, std::random_access_iterator_tag>::value,
|
||||
std::bidirectional_iterator_tag,
|
||||
typename std::iterator_traits<Iterator>::iterator_category
|
||||
typename sprout::min_iterator_category<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::bidirectional_iterator_tag
|
||||
>::type,
|
||||
typename std::iterator_traits<Iterator>::value_type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
|
@ -31,10 +29,9 @@ namespace sprout {
|
|||
public:
|
||||
typedef Predicate predicate_type;
|
||||
typedef Iterator iterator_type;
|
||||
typedef typename std::conditional<
|
||||
std::is_convertible<typename std::iterator_traits<Iterator>::iterator_category, std::random_access_iterator_tag>::value,
|
||||
std::bidirectional_iterator_tag,
|
||||
typename std::iterator_traits<Iterator>::iterator_category
|
||||
typedef typename sprout::min_iterator_category<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::bidirectional_iterator_tag
|
||||
>::type iterator_category;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
|
||||
|
@ -57,9 +54,7 @@ namespace sprout {
|
|||
Predicate pred;
|
||||
private:
|
||||
void satisfy_predicate() {
|
||||
while (current != last && !pred(*current)) {
|
||||
++current;
|
||||
}
|
||||
current = sprout::find_if(current, last, pred);
|
||||
}
|
||||
void satisfy_predicate_backward() {
|
||||
while (!pred(*current)) {
|
||||
|
|
50
sprout/iterator/unique_iterator.hpp
Normal file
50
sprout/iterator/unique_iterator.hpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#ifndef SPROUT_ITERATOR_UNIQUE_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_UNIQUE_ITERATOR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/adjacent_filter_iterator.hpp>
|
||||
#include <sprout/functional/equal_to.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// unique_filter
|
||||
//
|
||||
template<typename Predicate = sprout::equal_to<> >
|
||||
class unique_filter {
|
||||
public:
|
||||
typedef bool result_type;
|
||||
private:
|
||||
Predicate pred_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR unique_filter()
|
||||
: pred_()
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR unique_filter(Predicate pred)
|
||||
: pred_(pred)
|
||||
{}
|
||||
template<typename T, typename U>
|
||||
SPROUT_CONSTEXPR bool operator()(T const& lhs, U const& rhs) const {
|
||||
return !pred_(lhs, rhs);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// make_unique_iterator
|
||||
//
|
||||
template<typename Predicate, typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::adjacent_filter_iterator<sprout::unique_filter<Predicate>, Iterator>
|
||||
make_unique_iterator(Predicate pred, Iterator it, Iterator last = Iterator()) {
|
||||
return sprout::adjacent_filter_iterator<sprout::unique_filter<Predicate>, Iterator>(
|
||||
sprout::unique_filter<Predicate>(pred), it, last
|
||||
);
|
||||
}
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::adjacent_filter_iterator<sprout::unique_filter<>, Iterator>
|
||||
make_unique_iterator(Iterator it, Iterator last = Iterator()) {
|
||||
return sprout::adjacent_filter_iterator<sprout::unique_filter<>, Iterator>(
|
||||
sprout::unique_filter<>(), it, last
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // SPROUT_ITERATOR_UNIQUE_ITERATOR_HPP
|
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…
Reference in a new issue