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