From 9aa2a7c9b2fbd6cbadf9bbfe5d42be739baefcef Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 26 Jan 2013 23:51:43 +0900 Subject: [PATCH] add range adaptor: merged, set operations --- sprout/iterator/merge_iterator.hpp | 1 + sprout/iterator/remove_if_iterator.hpp | 2 +- sprout/iterator/remove_iterator.hpp | 2 +- sprout/iterator/set_difference_iterator.hpp | 2 +- sprout/iterator/set_intersection_iterator.hpp | 2 +- .../set_symmetric_difference_iterator.hpp | 4 +- sprout/iterator/set_union_iterator.hpp | 4 +- sprout/range/adaptor.hpp | 33 +--- sprout/range/adaptor/alternated.hpp | 1 - sprout/range/adaptor/amplitude_spectrum.hpp | 1 - sprout/range/adaptor/blanked.hpp | 1 - sprout/range/adaptor/clamped.hpp | 1 - sprout/range/adaptor/counting.hpp | 1 - sprout/range/adaptor/dft.hpp | 1 - sprout/range/adaptor/filled.hpp | 113 +++++++++++++ sprout/range/adaptor/filtered.hpp | 1 - sprout/range/adaptor/idft.hpp | 1 - sprout/range/adaptor/indexed.hpp | 1 - sprout/range/adaptor/jointed.hpp | 1 - sprout/range/adaptor/merged.hpp | 152 ++++++++++++++++++ sprout/range/adaptor/modifying.hpp | 21 +++ sprout/range/adaptor/outdirected.hpp | 1 - sprout/range/adaptor/phase_spectrum.hpp | 1 - sprout/range/adaptor/reduction.hpp | 18 +++ sprout/range/adaptor/removed.hpp | 116 +++++++++++++ sprout/range/adaptor/removed_if.hpp | 118 ++++++++++++++ sprout/range/adaptor/replaced.hpp | 1 - sprout/range/adaptor/replaced_if.hpp | 1 - sprout/range/adaptor/reversed.hpp | 1 - sprout/range/adaptor/sawtooth_wave.hpp | 1 - sprout/range/adaptor/set_difference.hpp | 152 ++++++++++++++++++ sprout/range/adaptor/set_intersection.hpp | 152 ++++++++++++++++++ .../adaptor/set_symmetric_difference.hpp | 152 ++++++++++++++++++ sprout/range/adaptor/set_union.hpp | 152 ++++++++++++++++++ sprout/range/adaptor/sinusoidal.hpp | 1 - sprout/range/adaptor/size_enumed.hpp | 1 - sprout/range/adaptor/sized.hpp | 1 - sprout/range/adaptor/square_wave.hpp | 1 - sprout/range/adaptor/steps.hpp | 1 - sprout/range/adaptor/transformed.hpp | 1 - sprout/range/adaptor/triangle_wave.hpp | 1 - sprout/range/adaptor/valued.hpp | 1 - sprout/range/adaptor/various.hpp | 18 +++ 43 files changed, 1176 insertions(+), 62 deletions(-) create mode 100644 sprout/range/adaptor/filled.hpp create mode 100644 sprout/range/adaptor/merged.hpp create mode 100644 sprout/range/adaptor/modifying.hpp create mode 100644 sprout/range/adaptor/reduction.hpp create mode 100644 sprout/range/adaptor/removed.hpp create mode 100644 sprout/range/adaptor/removed_if.hpp create mode 100644 sprout/range/adaptor/set_difference.hpp create mode 100644 sprout/range/adaptor/set_intersection.hpp create mode 100644 sprout/range/adaptor/set_symmetric_difference.hpp create mode 100644 sprout/range/adaptor/set_union.hpp create mode 100644 sprout/range/adaptor/various.hpp diff --git a/sprout/iterator/merge_iterator.hpp b/sprout/iterator/merge_iterator.hpp index 8aaf2cc4..95f73f04 100644 --- a/sprout/iterator/merge_iterator.hpp +++ b/sprout/iterator/merge_iterator.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace sprout { diff --git a/sprout/iterator/remove_if_iterator.hpp b/sprout/iterator/remove_if_iterator.hpp index 64f94b1d..ab4293a0 100644 --- a/sprout/iterator/remove_if_iterator.hpp +++ b/sprout/iterator/remove_if_iterator.hpp @@ -15,7 +15,7 @@ namespace sprout { private: Predicate pred_; public: - SPROUT_CONSTEXPR remove_if_filter(Predicate pred) + explicit SPROUT_CONSTEXPR remove_if_filter(Predicate pred) : pred_(pred) {} template diff --git a/sprout/iterator/remove_iterator.hpp b/sprout/iterator/remove_iterator.hpp index f0627c9a..0e9f0220 100644 --- a/sprout/iterator/remove_iterator.hpp +++ b/sprout/iterator/remove_iterator.hpp @@ -15,7 +15,7 @@ namespace sprout { private: T value_; public: - SPROUT_CONSTEXPR remove_filter(T const& value) + explicit SPROUT_CONSTEXPR remove_filter(T const& value) : value_(value) {} template diff --git a/sprout/iterator/set_difference_iterator.hpp b/sprout/iterator/set_difference_iterator.hpp index 8aa1ac04..a40eac5f 100644 --- a/sprout/iterator/set_difference_iterator.hpp +++ b/sprout/iterator/set_difference_iterator.hpp @@ -59,7 +59,7 @@ namespace sprout { , comp(other.comp) {} public: - set_difference_iterator() + SPROUT_CONSTEXPR set_difference_iterator() : current(), lst1(), lst2(), comp() {} set_difference_iterator(set_difference_iterator const&) = default; diff --git a/sprout/iterator/set_intersection_iterator.hpp b/sprout/iterator/set_intersection_iterator.hpp index a096386e..257aa291 100644 --- a/sprout/iterator/set_intersection_iterator.hpp +++ b/sprout/iterator/set_intersection_iterator.hpp @@ -59,7 +59,7 @@ namespace sprout { , comp(other.comp) {} public: - set_intersection_iterator() + SPROUT_CONSTEXPR set_intersection_iterator() : current(), lst1(), lst2(), comp() {} set_intersection_iterator(set_intersection_iterator const&) = default; diff --git a/sprout/iterator/set_symmetric_difference_iterator.hpp b/sprout/iterator/set_symmetric_difference_iterator.hpp index b30684f8..a76b5fbf 100644 --- a/sprout/iterator/set_symmetric_difference_iterator.hpp +++ b/sprout/iterator/set_symmetric_difference_iterator.hpp @@ -53,7 +53,7 @@ namespace sprout { protected: bool in_left; protected: - set_symmetric_difference_iterator_impl() + SPROUT_CONSTEXPR set_symmetric_difference_iterator_impl() : current(), lst1(), lst2(), comp(), in_left(true) {} set_symmetric_difference_iterator_impl(set_symmetric_difference_iterator_impl const&) = default; @@ -128,7 +128,7 @@ namespace sprout { : impl_type(next, other.lst1, other.lst2, other.comp) {} public: - set_symmetric_difference_iterator() + SPROUT_CONSTEXPR set_symmetric_difference_iterator() : impl_type() {} set_symmetric_difference_iterator(set_symmetric_difference_iterator const&) = default; diff --git a/sprout/iterator/set_union_iterator.hpp b/sprout/iterator/set_union_iterator.hpp index 0354d8a5..d4f6e1ce 100644 --- a/sprout/iterator/set_union_iterator.hpp +++ b/sprout/iterator/set_union_iterator.hpp @@ -69,10 +69,10 @@ namespace sprout { : current(next) , lst1(other.lst1), lst2(other.lst2) , comp(other.comp) - , in_left(check_in_left(next.first, lst1, next.second, lst2, comp)) + , in_left(check_in_left(next.first, other.lst1, next.second, other.lst2, other.comp)) {} public: - set_union_iterator() + SPROUT_CONSTEXPR set_union_iterator() : current(), lst1(), lst2(), comp(), in_left(true) {} set_union_iterator(set_union_iterator const&) = default; diff --git a/sprout/range/adaptor.hpp b/sprout/range/adaptor.hpp index fc727800..20334e17 100644 --- a/sprout/range/adaptor.hpp +++ b/sprout/range/adaptor.hpp @@ -2,36 +2,9 @@ #define SPROUT_RANGE_ADAPTOR_HPP #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include #endif // #ifndef SPROUT_RANGE_ADAPTOR_HPP diff --git a/sprout/range/adaptor/alternated.hpp b/sprout/range/adaptor/alternated.hpp index 6c172c25..5df4039e 100644 --- a/sprout/range/adaptor/alternated.hpp +++ b/sprout/range/adaptor/alternated.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/amplitude_spectrum.hpp b/sprout/range/adaptor/amplitude_spectrum.hpp index 80bb601d..96f4585b 100644 --- a/sprout/range/adaptor/amplitude_spectrum.hpp +++ b/sprout/range/adaptor/amplitude_spectrum.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/blanked.hpp b/sprout/range/adaptor/blanked.hpp index 369f630c..ad24a30e 100644 --- a/sprout/range/adaptor/blanked.hpp +++ b/sprout/range/adaptor/blanked.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/clamped.hpp b/sprout/range/adaptor/clamped.hpp index 8873f8b3..bef53a52 100644 --- a/sprout/range/adaptor/clamped.hpp +++ b/sprout/range/adaptor/clamped.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/counting.hpp b/sprout/range/adaptor/counting.hpp index 70c2bff9..43343dea 100644 --- a/sprout/range/adaptor/counting.hpp +++ b/sprout/range/adaptor/counting.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/dft.hpp b/sprout/range/adaptor/dft.hpp index 4d328d73..326835a0 100644 --- a/sprout/range/adaptor/dft.hpp +++ b/sprout/range/adaptor/dft.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/filled.hpp b/sprout/range/adaptor/filled.hpp new file mode 100644 index 00000000..745ee1f4 --- /dev/null +++ b/sprout/range/adaptor/filled.hpp @@ -0,0 +1,113 @@ +#ifndef SPROUT_RANGE_ADAPTOR_FILLED_HPP +#define SPROUT_RANGE_ADAPTOR_BLANKED_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace adaptors { + // + // filled_range + // + template + class filled_range + : public sprout::adaptors::detail::adapted_range_default< + Range, + sprout::value_iterator::value_type> + > + { + public: + typedef sprout::adaptors::detail::adapted_range_default< + Range, + sprout::value_iterator::value_type> + > base_type; + typedef typename base_type::range_type range_type; + typedef typename base_type::iterator iterator; + typedef typename base_type::value_type value_type; + public: + filled_range() = default; + filled_range(filled_range const&) = default; + SPROUT_CONSTEXPR filled_range( + range_type& range, + value_type const& value + ) + : base_type( + iterator(value, sprout::size(range)), + iterator(value, 0) + ) + {} + }; + + // + // fill_holder + // + template + class fill_holder { + public: + typedef T value_type; + private: + value_type value_; + public: + explicit SPROUT_CONSTEXPR fill_holder(value_type const& value) + : value_(value) + {} + SPROUT_CONSTEXPR value_type const& value() const { + return value_; + } + }; + + // + // filled_forwarder + // + class filled_forwarder { + public: + template + SPROUT_CONSTEXPR sprout::adaptors::fill_holder + operator()(T const& value) const { + return sprout::adaptors::fill_holder(value); + } + }; + + // + // filled + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::adaptors::filled_forwarder filled = {}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR sprout::adaptors::filled_range< + typename std::remove_reference::type>::type + > + operator|(Range&& lhs, sprout::adaptors::fill_holder const& rhs) { + return sprout::adaptors::filled_range< + typename std::remove_reference::type>::type + >( + sprout::lvalue_forward(lhs), + rhs.value() + ); + } + } // namespace adaptors + + // + // container_construct_traits + // + template + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_BLANKED_HPP diff --git a/sprout/range/adaptor/filtered.hpp b/sprout/range/adaptor/filtered.hpp index 58c97e7f..369e47e6 100644 --- a/sprout/range/adaptor/filtered.hpp +++ b/sprout/range/adaptor/filtered.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/idft.hpp b/sprout/range/adaptor/idft.hpp index f549d65d..e6afdbaf 100644 --- a/sprout/range/adaptor/idft.hpp +++ b/sprout/range/adaptor/idft.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/indexed.hpp b/sprout/range/adaptor/indexed.hpp index 265b8de2..4d436f03 100644 --- a/sprout/range/adaptor/indexed.hpp +++ b/sprout/range/adaptor/indexed.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/jointed.hpp b/sprout/range/adaptor/jointed.hpp index 4af8fb43..bb3b3697 100644 --- a/sprout/range/adaptor/jointed.hpp +++ b/sprout/range/adaptor/jointed.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/merged.hpp b/sprout/range/adaptor/merged.hpp new file mode 100644 index 00000000..28b5586e --- /dev/null +++ b/sprout/range/adaptor/merged.hpp @@ -0,0 +1,152 @@ +#ifndef SPROUT_RANGE_ADAPTOR_MERGED_HPP +#define SPROUT_RANGE_ADAPTOR_MERGED_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace adaptors { + // + // merged_range + // + template > + class merged_range + : public sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::merge_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > + { + public: + typedef sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::merge_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > base_type; + typedef typename base_type::range1_type range1_type; + typedef typename base_type::range2_type range2_type; + typedef typename base_type::iterator iterator; + public: + merged_range() = default; + merged_range(merged_range const&) = default; + SPROUT_CONSTEXPR merged_range(range1_type& range1, range2_type& range2, Compare comp = Compare()) + : base_type( + iterator(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2), comp), + iterator(sprout::end(range1), sprout::end(range1), sprout::end(range2), sprout::end(range2), comp) + ) + {} + }; + + // + // merge_holder + // + template > + class merge_holder { + public: + typedef RRange range2_type; + typedef Compare compare_type; + private: + sprout::value_holder range_; + Compare comp_; + public: + merge_holder() = default; + merge_holder(merge_holder const&) = default; + explicit SPROUT_CONSTEXPR merge_holder(range2_type& range, Compare comp = Compare()) + : range_(range) + , comp_(comp) + {} + SPROUT_CONSTEXPR range2_type& range() const { + return range_; + } + SPROUT_CONSTEXPR Compare compare() const { + return comp_; + } + }; + + // + // merged_forwarder + // + class merged_forwarder { + public: + template + SPROUT_CONSTEXPR sprout::adaptors::merge_holder< + typename std::remove_reference::type>::type + > + operator()(RRange&& range) { + return sprout::adaptors::merge_holder< + typename std::remove_reference::type>::type + >( + sprout::lvalue_forward(range) + ); + } + template + SPROUT_CONSTEXPR sprout::adaptors::merge_holder< + typename std::remove_reference::type>::type, + Compare + > + operator()(RRange&& range, Compare comp) { + return sprout::adaptors::merge_holder< + typename std::remove_reference::type>::type, + Compare + >( + sprout::lvalue_forward(range), + comp + ); + } + }; + + // + // merged + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::adaptors::merged_forwarder merged = {}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR sprout::adaptors::merged_range< + typename std::remove_reference::type>::type, + RRange, + Compare + > + operator|(LRange&& lhs, sprout::adaptors::merge_holder const& rhs) { + return sprout::adaptors::merged_range< + typename std::remove_reference::type>::type, + RRange, + Compare + >( + sprout::lvalue_forward(lhs), + rhs.range(), + rhs.compare() + ); + } + } // namespace adaptors + + // + // container_construct_traits + // + template + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_MERGED_HPP diff --git a/sprout/range/adaptor/modifying.hpp b/sprout/range/adaptor/modifying.hpp new file mode 100644 index 00000000..9ce6e1df --- /dev/null +++ b/sprout/range/adaptor/modifying.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ADAPTOR_MODIFYING_HPP +#define SPROUT_RANGE_ADAPTOR_MODIFYING_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_MODIFYING_HPP diff --git a/sprout/range/adaptor/outdirected.hpp b/sprout/range/adaptor/outdirected.hpp index 11a97992..f4f8fa66 100644 --- a/sprout/range/adaptor/outdirected.hpp +++ b/sprout/range/adaptor/outdirected.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/phase_spectrum.hpp b/sprout/range/adaptor/phase_spectrum.hpp index 39aeeb52..c0a34f52 100644 --- a/sprout/range/adaptor/phase_spectrum.hpp +++ b/sprout/range/adaptor/phase_spectrum.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/reduction.hpp b/sprout/range/adaptor/reduction.hpp new file mode 100644 index 00000000..91c8c06b --- /dev/null +++ b/sprout/range/adaptor/reduction.hpp @@ -0,0 +1,18 @@ +#ifndef SPROUT_RANGE_ADAPTOR_REDUCTION_HPP +#define SPROUT_RANGE_ADAPTOR_REDUCTION_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_REDUCTION_HPP diff --git a/sprout/range/adaptor/removed.hpp b/sprout/range/adaptor/removed.hpp new file mode 100644 index 00000000..8d34d645 --- /dev/null +++ b/sprout/range/adaptor/removed.hpp @@ -0,0 +1,116 @@ +#ifndef SPROUT_RANGE_ADAPTOR_REMOVED_HPP +#define SPROUT_RANGE_ADAPTOR_REMOVED_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace adaptors { + // + // removed_range + // + template + class removed_range + : public sprout::adaptors::detail::adapted_range_default< + Range, + sprout::filter_iterator< + sprout::remove_filter::value_type>, + typename sprout::container_traits::iterator + > + > + { + public: + typedef sprout::adaptors::detail::adapted_range_default< + Range, + sprout::filter_iterator< + sprout::remove_filter::value_type>, + typename sprout::container_traits::iterator + > + > base_type; + typedef typename base_type::range_type range_type; + typedef typename base_type::iterator iterator; + typedef typename base_type::value_type value_type; + public: + removed_range() = default; + removed_range(removed_range const&) = default; + SPROUT_CONSTEXPR removed_range(range_type& range, value_type const& value) + : base_type( + iterator(sprout::begin(range), typename iterator::predicate_type(value)), + iterator(sprout::end(range), typename iterator::predicate_type(value)) + ) + {} + }; + + // + // remove_holder + // + template + class remove_holder { + public: + typedef T value_type; + private: + value_type value_; + public: + explicit SPROUT_CONSTEXPR remove_holder(value_type const& value) + : value_(value) + {} + SPROUT_CONSTEXPR value_type const& value() const { + return value_; + } + }; + + // + // removed_forwarder + // + class removed_forwarder { + public: + template + SPROUT_CONSTEXPR sprout::adaptors::remove_holder + operator()(T const& value) { + return sprout::adaptors::remove_holder(value); + } + }; + + // + // removed + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::adaptors::removed_forwarder removed = {}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR sprout::adaptors::removed_range< + typename std::remove_reference::type>::type + > + operator|(Range&& lhs, sprout::adaptors::remove_holder const& rhs) { + return sprout::adaptors::removed_range< + typename std::remove_reference::type>::type + >( + sprout::lvalue_forward(lhs), + rhs.value() + ); + } + } // namespace adaptors + + // + // container_construct_traits + // + template + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_REMOVED_HPP diff --git a/sprout/range/adaptor/removed_if.hpp b/sprout/range/adaptor/removed_if.hpp new file mode 100644 index 00000000..5900f33e --- /dev/null +++ b/sprout/range/adaptor/removed_if.hpp @@ -0,0 +1,118 @@ +#ifndef SPROUT_RANGE_ADAPTOR_REMOVED_IF_HPP +#define SPROUT_RANGE_ADAPTOR_REMOVED_IF_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace adaptors { + // + // removed_if_range + // + template + class removed_if_range + : public sprout::adaptors::detail::adapted_range_default< + Range, + sprout::filter_iterator< + sprout::remove_if_filter, + typename sprout::container_traits::iterator + > + > + { + public: + typedef Predicate predicate_type; + typedef sprout::adaptors::detail::adapted_range_default< + Range, + sprout::filter_iterator< + sprout::remove_if_filter, + typename sprout::container_traits::iterator + > + > base_type; + typedef typename base_type::range_type range_type; + typedef typename base_type::iterator iterator; + public: + removed_if_range() = default; + removed_if_range(removed_if_range const&) = default; + SPROUT_CONSTEXPR removed_if_range(range_type& range, Predicate pred) + : base_type( + iterator(sprout::begin(range), typename iterator::predicate_type(pred)), + iterator(sprout::end(range), typename iterator::predicate_type(pred)) + ) + {} + }; + + // + // remove_if_holder + // + template + class remove_if_holder { + public: + typedef Predicate predicate_type; + private: + Predicate pred_; + public: + explicit SPROUT_CONSTEXPR remove_if_holder(Predicate pred) + : pred_(pred) + {} + SPROUT_CONSTEXPR Predicate const& predicate() const { + return pred_; + } + }; + + // + // removed_if_forwarder + // + class removed_if_forwarder { + public: + template + SPROUT_CONSTEXPR sprout::adaptors::remove_if_holder + operator()(Predicate pred) { + return sprout::adaptors::remove_if_holder(pred); + } + }; + + // + // removed_if + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::adaptors::removed_if_forwarder removed_if = {}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR sprout::adaptors::removed_if_range< + Predicate, + typename std::remove_reference::type>::type + > + operator|(Range&& lhs, sprout::adaptors::remove_if_holder const& rhs) { + return sprout::adaptors::removed_if_range< + Predicate, + typename std::remove_reference::type>::type + >( + sprout::lvalue_forward(lhs), + rhs.predicate() + ); + } + } // namespace adaptors + + // + // container_construct_traits + // + template + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_REMOVED_IF_HPP diff --git a/sprout/range/adaptor/replaced.hpp b/sprout/range/adaptor/replaced.hpp index 67ee7cd2..b97dbb99 100644 --- a/sprout/range/adaptor/replaced.hpp +++ b/sprout/range/adaptor/replaced.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/replaced_if.hpp b/sprout/range/adaptor/replaced_if.hpp index 842b0d2b..1c50ab0c 100644 --- a/sprout/range/adaptor/replaced_if.hpp +++ b/sprout/range/adaptor/replaced_if.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/reversed.hpp b/sprout/range/adaptor/reversed.hpp index 698ff44a..a7a02e47 100644 --- a/sprout/range/adaptor/reversed.hpp +++ b/sprout/range/adaptor/reversed.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/sawtooth_wave.hpp b/sprout/range/adaptor/sawtooth_wave.hpp index 2a9a8cc2..48192175 100644 --- a/sprout/range/adaptor/sawtooth_wave.hpp +++ b/sprout/range/adaptor/sawtooth_wave.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/set_difference.hpp b/sprout/range/adaptor/set_difference.hpp new file mode 100644 index 00000000..03b566e0 --- /dev/null +++ b/sprout/range/adaptor/set_difference.hpp @@ -0,0 +1,152 @@ +#ifndef SPROUT_RANGE_ADAPTOR_SET_DIFFERENCE_HPP +#define SPROUT_RANGE_ADAPTOR_SET_DIFFERENCE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace adaptors { + // + // set_difference_range + // + template > + class set_difference_range + : public sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::set_difference_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > + { + public: + typedef sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::set_difference_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > base_type; + typedef typename base_type::range1_type range1_type; + typedef typename base_type::range2_type range2_type; + typedef typename base_type::iterator iterator; + public: + set_difference_range() = default; + set_difference_range(set_difference_range const&) = default; + SPROUT_CONSTEXPR set_difference_range(range1_type& range1, range2_type& range2, Compare comp = Compare()) + : base_type( + iterator(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2), comp), + iterator(sprout::end(range1), sprout::end(range1), sprout::end(range2), sprout::end(range2), comp) + ) + {} + }; + + // + // set_difference_holder + // + template > + class set_difference_holder { + public: + typedef RRange range2_type; + typedef Compare compare_type; + private: + sprout::value_holder range_; + Compare comp_; + public: + set_difference_holder() = default; + set_difference_holder(set_difference_holder const&) = default; + explicit SPROUT_CONSTEXPR set_difference_holder(range2_type& range, Compare comp = Compare()) + : range_(range) + , comp_(comp) + {} + SPROUT_CONSTEXPR range2_type& range() const { + return range_; + } + SPROUT_CONSTEXPR Compare compare() const { + return comp_; + } + }; + + // + // set_difference_forwarder + // + class set_difference_forwarder { + public: + template + SPROUT_CONSTEXPR sprout::adaptors::set_difference_holder< + typename std::remove_reference::type>::type + > + operator()(RRange&& range) { + return sprout::adaptors::set_difference_holder< + typename std::remove_reference::type>::type + >( + sprout::lvalue_forward(range) + ); + } + template + SPROUT_CONSTEXPR sprout::adaptors::set_difference_holder< + typename std::remove_reference::type>::type, + Compare + > + operator()(RRange&& range, Compare comp) { + return sprout::adaptors::set_difference_holder< + typename std::remove_reference::type>::type, + Compare + >( + sprout::lvalue_forward(range), + comp + ); + } + }; + + // + // set_difference + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::adaptors::set_difference_forwarder set_difference = {}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR sprout::adaptors::set_difference_range< + typename std::remove_reference::type>::type, + RRange, + Compare + > + operator|(LRange&& lhs, sprout::adaptors::set_difference_holder const& rhs) { + return sprout::adaptors::set_difference_range< + typename std::remove_reference::type>::type, + RRange, + Compare + >( + sprout::lvalue_forward(lhs), + rhs.range(), + rhs.compare() + ); + } + } // namespace adaptors + + // + // container_construct_traits + // + template + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_SET_DIFFERENCE_HPP diff --git a/sprout/range/adaptor/set_intersection.hpp b/sprout/range/adaptor/set_intersection.hpp new file mode 100644 index 00000000..7b68ef54 --- /dev/null +++ b/sprout/range/adaptor/set_intersection.hpp @@ -0,0 +1,152 @@ +#ifndef SPROUT_RANGE_ADAPTOR_SET_INTERSECTION_HPP +#define SPROUT_RANGE_ADAPTOR_SET_INTERSECTION_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace adaptors { + // + // set_intersection_range + // + template > + class set_intersection_range + : public sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::set_intersection_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > + { + public: + typedef sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::set_intersection_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > base_type; + typedef typename base_type::range1_type range1_type; + typedef typename base_type::range2_type range2_type; + typedef typename base_type::iterator iterator; + public: + set_intersection_range() = default; + set_intersection_range(set_intersection_range const&) = default; + SPROUT_CONSTEXPR set_intersection_range(range1_type& range1, range2_type& range2, Compare comp = Compare()) + : base_type( + iterator(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2), comp), + iterator(sprout::end(range1), sprout::end(range1), sprout::end(range2), sprout::end(range2), comp) + ) + {} + }; + + // + // set_intersection_holder + // + template > + class set_intersection_holder { + public: + typedef RRange range2_type; + typedef Compare compare_type; + private: + sprout::value_holder range_; + Compare comp_; + public: + set_intersection_holder() = default; + set_intersection_holder(set_intersection_holder const&) = default; + explicit SPROUT_CONSTEXPR set_intersection_holder(range2_type& range, Compare comp = Compare()) + : range_(range) + , comp_(comp) + {} + SPROUT_CONSTEXPR range2_type& range() const { + return range_; + } + SPROUT_CONSTEXPR Compare compare() const { + return comp_; + } + }; + + // + // set_intersection_forwarder + // + class set_intersection_forwarder { + public: + template + SPROUT_CONSTEXPR sprout::adaptors::set_intersection_holder< + typename std::remove_reference::type>::type + > + operator()(RRange&& range) { + return sprout::adaptors::set_intersection_holder< + typename std::remove_reference::type>::type + >( + sprout::lvalue_forward(range) + ); + } + template + SPROUT_CONSTEXPR sprout::adaptors::set_intersection_holder< + typename std::remove_reference::type>::type, + Compare + > + operator()(RRange&& range, Compare comp) { + return sprout::adaptors::set_intersection_holder< + typename std::remove_reference::type>::type, + Compare + >( + sprout::lvalue_forward(range), + comp + ); + } + }; + + // + // set_intersection + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::adaptors::set_intersection_forwarder set_intersection = {}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR sprout::adaptors::set_intersection_range< + typename std::remove_reference::type>::type, + RRange, + Compare + > + operator|(LRange&& lhs, sprout::adaptors::set_intersection_holder const& rhs) { + return sprout::adaptors::set_intersection_range< + typename std::remove_reference::type>::type, + RRange, + Compare + >( + sprout::lvalue_forward(lhs), + rhs.range(), + rhs.compare() + ); + } + } // namespace adaptors + + // + // container_construct_traits + // + template + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_SET_INTERSECTION_HPP diff --git a/sprout/range/adaptor/set_symmetric_difference.hpp b/sprout/range/adaptor/set_symmetric_difference.hpp new file mode 100644 index 00000000..62699015 --- /dev/null +++ b/sprout/range/adaptor/set_symmetric_difference.hpp @@ -0,0 +1,152 @@ +#ifndef SPROUT_RANGE_ADAPTOR_SET_SYMMETRIC_DIFFERENCE_HPP +#define SPROUT_RANGE_ADAPTOR_SET_SYMMETRIC_DIFFERENCE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace adaptors { + // + // set_symmetric_difference_range + // + template > + class set_symmetric_difference_range + : public sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::set_symmetric_difference_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > + { + public: + typedef sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::set_symmetric_difference_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > base_type; + typedef typename base_type::range1_type range1_type; + typedef typename base_type::range2_type range2_type; + typedef typename base_type::iterator iterator; + public: + set_symmetric_difference_range() = default; + set_symmetric_difference_range(set_symmetric_difference_range const&) = default; + SPROUT_CONSTEXPR set_symmetric_difference_range(range1_type& range1, range2_type& range2, Compare comp = Compare()) + : base_type( + iterator(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2), comp), + iterator(sprout::end(range1), sprout::end(range1), sprout::end(range2), sprout::end(range2), comp) + ) + {} + }; + + // + // set_symmetric_difference_holder + // + template > + class set_symmetric_difference_holder { + public: + typedef RRange range2_type; + typedef Compare compare_type; + private: + sprout::value_holder range_; + Compare comp_; + public: + set_symmetric_difference_holder() = default; + set_symmetric_difference_holder(set_symmetric_difference_holder const&) = default; + explicit SPROUT_CONSTEXPR set_symmetric_difference_holder(range2_type& range, Compare comp = Compare()) + : range_(range) + , comp_(comp) + {} + SPROUT_CONSTEXPR range2_type& range() const { + return range_; + } + SPROUT_CONSTEXPR Compare compare() const { + return comp_; + } + }; + + // + // set_symmetric_difference_forwarder + // + class set_symmetric_difference_forwarder { + public: + template + SPROUT_CONSTEXPR sprout::adaptors::set_symmetric_difference_holder< + typename std::remove_reference::type>::type + > + operator()(RRange&& range) { + return sprout::adaptors::set_symmetric_difference_holder< + typename std::remove_reference::type>::type + >( + sprout::lvalue_forward(range) + ); + } + template + SPROUT_CONSTEXPR sprout::adaptors::set_symmetric_difference_holder< + typename std::remove_reference::type>::type, + Compare + > + operator()(RRange&& range, Compare comp) { + return sprout::adaptors::set_symmetric_difference_holder< + typename std::remove_reference::type>::type, + Compare + >( + sprout::lvalue_forward(range), + comp + ); + } + }; + + // + // set_symmetric_difference + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::adaptors::set_symmetric_difference_forwarder set_symmetric_difference = {}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR sprout::adaptors::set_symmetric_difference_range< + typename std::remove_reference::type>::type, + RRange, + Compare + > + operator|(LRange&& lhs, sprout::adaptors::set_symmetric_difference_holder const& rhs) { + return sprout::adaptors::set_symmetric_difference_range< + typename std::remove_reference::type>::type, + RRange, + Compare + >( + sprout::lvalue_forward(lhs), + rhs.range(), + rhs.compare() + ); + } + } // namespace adaptors + + // + // container_construct_traits + // + template + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_SET_SYMMETRIC_DIFFERENCE_HPP diff --git a/sprout/range/adaptor/set_union.hpp b/sprout/range/adaptor/set_union.hpp new file mode 100644 index 00000000..3c17b14e --- /dev/null +++ b/sprout/range/adaptor/set_union.hpp @@ -0,0 +1,152 @@ +#ifndef SPROUT_RANGE_ADAPTOR_SET_UNION_HPP +#define SPROUT_RANGE_ADAPTOR_SET_UNION_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace adaptors { + // + // set_union_range + // + template > + class set_union_range + : public sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::set_union_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > + { + public: + typedef sprout::adaptors::detail::jointed_range_default< + LRange, RRange, + sprout::set_union_iterator< + typename sprout::container_traits::iterator, + typename sprout::container_traits::iterator, + Compare + > + > base_type; + typedef typename base_type::range1_type range1_type; + typedef typename base_type::range2_type range2_type; + typedef typename base_type::iterator iterator; + public: + set_union_range() = default; + set_union_range(set_union_range const&) = default; + SPROUT_CONSTEXPR set_union_range(range1_type& range1, range2_type& range2, Compare comp = Compare()) + : base_type( + iterator(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2), comp), + iterator(sprout::end(range1), sprout::end(range1), sprout::end(range2), sprout::end(range2), comp) + ) + {} + }; + + // + // set_union_holder + // + template > + class set_union_holder { + public: + typedef RRange range2_type; + typedef Compare compare_type; + private: + sprout::value_holder range_; + Compare comp_; + public: + set_union_holder() = default; + set_union_holder(set_union_holder const&) = default; + explicit SPROUT_CONSTEXPR set_union_holder(range2_type& range, Compare comp = Compare()) + : range_(range) + , comp_(comp) + {} + SPROUT_CONSTEXPR range2_type& range() const { + return range_; + } + SPROUT_CONSTEXPR Compare compare() const { + return comp_; + } + }; + + // + // set_union_forwarder + // + class set_union_forwarder { + public: + template + SPROUT_CONSTEXPR sprout::adaptors::set_union_holder< + typename std::remove_reference::type>::type + > + operator()(RRange&& range) { + return sprout::adaptors::set_union_holder< + typename std::remove_reference::type>::type + >( + sprout::lvalue_forward(range) + ); + } + template + SPROUT_CONSTEXPR sprout::adaptors::set_union_holder< + typename std::remove_reference::type>::type, + Compare + > + operator()(RRange&& range, Compare comp) { + return sprout::adaptors::set_union_holder< + typename std::remove_reference::type>::type, + Compare + >( + sprout::lvalue_forward(range), + comp + ); + } + }; + + // + // set_union + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::adaptors::set_union_forwarder set_union = {}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR sprout::adaptors::set_union_range< + typename std::remove_reference::type>::type, + RRange, + Compare + > + operator|(LRange&& lhs, sprout::adaptors::set_union_holder const& rhs) { + return sprout::adaptors::set_union_range< + typename std::remove_reference::type>::type, + RRange, + Compare + >( + sprout::lvalue_forward(lhs), + rhs.range(), + rhs.compare() + ); + } + } // namespace adaptors + + // + // container_construct_traits + // + template + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_SET_UNION_HPP diff --git a/sprout/range/adaptor/sinusoidal.hpp b/sprout/range/adaptor/sinusoidal.hpp index 39da39db..2754277c 100644 --- a/sprout/range/adaptor/sinusoidal.hpp +++ b/sprout/range/adaptor/sinusoidal.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/size_enumed.hpp b/sprout/range/adaptor/size_enumed.hpp index c0fd2a30..4a9f488e 100644 --- a/sprout/range/adaptor/size_enumed.hpp +++ b/sprout/range/adaptor/size_enumed.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/sized.hpp b/sprout/range/adaptor/sized.hpp index 1bbc92d7..21ccd198 100644 --- a/sprout/range/adaptor/sized.hpp +++ b/sprout/range/adaptor/sized.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/square_wave.hpp b/sprout/range/adaptor/square_wave.hpp index b19f9ae1..ac5f4667 100644 --- a/sprout/range/adaptor/square_wave.hpp +++ b/sprout/range/adaptor/square_wave.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/steps.hpp b/sprout/range/adaptor/steps.hpp index f5c540a2..8f2de442 100644 --- a/sprout/range/adaptor/steps.hpp +++ b/sprout/range/adaptor/steps.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/transformed.hpp b/sprout/range/adaptor/transformed.hpp index 9cbdbe97..1cbc57a3 100644 --- a/sprout/range/adaptor/transformed.hpp +++ b/sprout/range/adaptor/transformed.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/triangle_wave.hpp b/sprout/range/adaptor/triangle_wave.hpp index 5a81b4e7..fc2c1148 100644 --- a/sprout/range/adaptor/triangle_wave.hpp +++ b/sprout/range/adaptor/triangle_wave.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/valued.hpp b/sprout/range/adaptor/valued.hpp index cd8567ed..cdda4b89 100644 --- a/sprout/range/adaptor/valued.hpp +++ b/sprout/range/adaptor/valued.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/range/adaptor/various.hpp b/sprout/range/adaptor/various.hpp new file mode 100644 index 00000000..5e826009 --- /dev/null +++ b/sprout/range/adaptor/various.hpp @@ -0,0 +1,18 @@ +#ifndef SPROUT_RANGE_ADAPTOR_VARIOUS_HPP +#define SPROUT_RANGE_ADAPTOR_VARIOUS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_VARIOUS_HPP