File indexing completed on 2025-01-18 10:09:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_ACTION_UNIQUE_HPP
0015 #define RANGES_V3_ACTION_UNIQUE_HPP
0016
0017 #include <range/v3/range_fwd.hpp>
0018
0019 #include <range/v3/action/action.hpp>
0020 #include <range/v3/action/erase.hpp>
0021 #include <range/v3/algorithm/unique.hpp>
0022 #include <range/v3/functional/bind_back.hpp>
0023 #include <range/v3/functional/comparisons.hpp>
0024 #include <range/v3/functional/identity.hpp>
0025 #include <range/v3/iterator/concepts.hpp>
0026 #include <range/v3/range/traits.hpp>
0027 #include <range/v3/utility/static_const.hpp>
0028
0029 #include <range/v3/detail/prologue.hpp>
0030
0031 namespace ranges
0032 {
0033
0034
0035 namespace actions
0036 {
0037 struct unique_fn
0038 {
0039 template(typename C, typename P = identity)(
0040 requires (!range<C>))
0041 constexpr auto operator()(C pred, P proj = P{}) const
0042 {
0043 return make_action_closure(
0044 bind_back(unique_fn{}, std::move(pred), std::move(proj)));
0045 }
0046
0047 template(typename Rng, typename C = equal_to, typename P = identity)(
0048 requires forward_range<Rng> AND
0049 erasable_range<Rng &, iterator_t<Rng>, sentinel_t<Rng>> AND
0050 sortable<iterator_t<Rng>, C, P>)
0051 Rng operator()(Rng && rng, C pred = C{}, P proj = P{}) const
0052 {
0053 auto it = ranges::unique(rng, std::move(pred), std::move(proj));
0054 ranges::erase(rng, it, end(rng));
0055 return static_cast<Rng &&>(rng);
0056 }
0057 };
0058
0059
0060
0061 RANGES_INLINE_VARIABLE(action_closure<unique_fn>, unique)
0062 }
0063
0064 }
0065
0066 #include <range/v3/detail/epilogue.hpp>
0067
0068 #endif