tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
unique.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_UNIQUE_HPP
4#define TETL_ALGORITHM_UNIQUE_HPP
5
8
9namespace etl {
10
13
17template <typename ForwardIt, typename Predicate>
18constexpr auto unique(ForwardIt first, ForwardIt last, Predicate pred) -> ForwardIt
19{
20 if (first == last) {
21 return last;
22 }
23
24 auto result = first;
25 while (++first != last) {
26 if (not pred(*result, *first) and ++result != first) {
27 *result = etl::move(*first);
28 }
29 }
30 return ++result;
31}
32
33template <typename ForwardIt>
34constexpr auto unique(ForwardIt first, ForwardIt last) -> ForwardIt
35{
36 return etl::unique(first, last, etl::equal_to());
37}
38
40
41} // namespace etl
42
43#endif // TETL_ALGORITHM_UNIQUE_HPP
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
constexpr auto unique(ForwardIt first, ForwardIt last, Predicate pred) -> ForwardIt
Eliminates all except the first element from every consecutive group of equivalent elements from the ...
Definition unique.hpp:18
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator== on type T....
Definition equal_to.hpp:14