File indexing completed on 2025-12-16 10:27:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_ALGORITHM_ADJACENT_REMOVE_IF_HPP
0015 #define RANGES_V3_ALGORITHM_ADJACENT_REMOVE_IF_HPP
0016
0017 #include <functional>
0018 #include <utility>
0019
0020 #include <range/v3/range_fwd.hpp>
0021
0022 #include <range/v3/algorithm/adjacent_find.hpp>
0023 #include <range/v3/algorithm/move.hpp>
0024 #include <range/v3/functional/identity.hpp>
0025 #include <range/v3/functional/invoke.hpp>
0026 #include <range/v3/iterator/concepts.hpp>
0027 #include <range/v3/iterator/traits.hpp>
0028 #include <range/v3/range/access.hpp>
0029 #include <range/v3/range/concepts.hpp>
0030 #include <range/v3/range/traits.hpp>
0031 #include <range/v3/utility/move.hpp>
0032 #include <range/v3/utility/static_const.hpp>
0033
0034 #include <range/v3/detail/prologue.hpp>
0035
0036 namespace ranges
0037 {
0038
0039
0040 RANGES_FUNC_BEGIN(adjacent_remove_if)
0041
0042
0043
0044
0045
0046
0047 template(typename I, typename S, typename Pred, typename Proj = identity)(
0048 requires permutable<I> AND sentinel_for<S, I> AND
0049 indirect_relation<Pred, projected<I, Proj>>)
0050 constexpr I RANGES_FUNC(adjacent_remove_if)(I first, S last, Pred pred = {}, Proj proj = {})
0051 {
0052 first = adjacent_find(std::move(first), last, ranges::ref(pred), ranges::ref(proj));
0053 if(first == last)
0054 return first;
0055
0056 auto i = first;
0057 for(auto j = ++i; ++j != last; ++i)
0058 {
0059 if(!invoke(pred, invoke(proj, *i), invoke(proj, *j)))
0060 {
0061 *first = iter_move(i);
0062 ++first;
0063 }
0064 }
0065
0066 *first = iter_move(i);
0067 ++first;
0068 return first;
0069 }
0070
0071
0072 template(typename Rng, typename Pred, typename Proj = identity)(
0073 requires forward_range<Rng> AND
0074 indirect_relation<Pred, projected<iterator_t<Rng>, Proj>> AND
0075 permutable<iterator_t<Rng>>)
0076 constexpr borrowed_iterator_t<Rng>
0077 RANGES_FUNC(adjacent_remove_if)(Rng && rng, Pred pred, Proj proj = {})
0078 {
0079 return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
0080 }
0081 RANGES_FUNC_END(adjacent_remove_if)
0082
0083 namespace cpp20
0084 {
0085 using ranges::adjacent_remove_if;
0086 }
0087
0088 }
0089
0090 #include <range/v3/detail/epilogue.hpp>
0091
0092 #endif