Horizon
Loading...
Searching...
No Matches
unique.hpp
Go to the documentation of this file.
1
2// Range v3 library
3//
4// Copyright Eric Niebler 2013-present
5// Copyright Gonzalo Brito Gadeschi 2014
6//
7// Use, modification and distribution is subject to the
8// Boost Software License, Version 1.0. (See accompanying
9// file LICENSE_1_0.txt or copy at
10// http://www.boost.org/LICENSE_1_0.txt)
11//
12// Project home: https://github.com/ericniebler/range-v3
13//
14// Implementation based on the code in libc++
15// http://http://libcxx.llvm.org/
16
17#ifndef RANGES_V3_ALGORITHM_UNIQUE_HPP
18#define RANGES_V3_ALGORITHM_UNIQUE_HPP
19
21
31#include <range/v3/utility/static_const.hpp>
32
33#include <range/v3/detail/prologue.hpp>
34
35namespace ranges
36{
39 RANGES_FUNC_BEGIN(unique)
40
41
50 template(typename I, typename S, typename C = equal_to, typename P = identity)(
51 requires sortable<I, C, P> AND sentinel_for<S, I>)
52 constexpr I RANGES_FUNC(unique)(I first, S last, C pred = C{}, P proj = P{})
53 {
54 first = adjacent_find(std::move(first), last, ranges::ref(pred), ranges::ref(proj));
55
56 if(first != last)
57 {
58 for(I i = next(first); ++i != last;)
59 if(!invoke(pred, invoke(proj, *first), invoke(proj, *i)))
60 *++first = iter_move(i);
61 ++first;
62 }
63 return first;
64 }
65
67 template(typename Rng, typename C = equal_to, typename P = identity)(
68 requires sortable<iterator_t<Rng>, C, P> AND range<Rng>)
69 constexpr borrowed_iterator_t<Rng> //
70 RANGES_FUNC(unique)(Rng && rng, C pred = C{}, P proj = P{}) //
71 {
72 return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
73 }
74
75 RANGES_FUNC_END(unique)
76
77 namespace cpp20
78 {
79 using ranges::unique;
80 }
82} // namespace ranges
83
84#include <range/v3/detail/epilogue.hpp>
85
86#endif
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition meta.hpp:541
front< Pair > first
Retrieve the first element of the pair Pair.
Definition meta.hpp:2251
bool_< T::type::value==U::type::value > equal_to
A Boolean integral constant wrapper around the result of comparing T::type::value and U::type::value ...
Definition meta.hpp:237