tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
adjacent_find.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_ADJACENT_FIND_HPP
4#define TETL_ALGORITHM_ADJACENT_FIND_HPP
5
7
8namespace etl {
11
21template <typename ForwardIt, typename Predicate>
22[[nodiscard]] constexpr auto adjacent_find(ForwardIt first, ForwardIt last, Predicate pred) -> ForwardIt
23{
24 if (first == last) {
25 return last;
26 }
27
28 auto next = first;
29 ++next;
30
31 for (; next != last; ++next, (void)++first) {
32 if (pred(*first, *next)) {
33 return first;
34 }
35 }
36
37 return last;
38}
39
40template <typename ForwardIt>
41[[nodiscard]] constexpr auto adjacent_find(ForwardIt first, ForwardIt last) -> ForwardIt
42{
43 return etl::adjacent_find(first, last, etl::equal_to());
44}
45
47
48} // namespace etl
49
50#endif // TETL_ALGORITHM_ADJACENT_FIND_HPP
constexpr auto adjacent_find(ForwardIt first, ForwardIt last, Predicate pred) -> ForwardIt
Searches the range [first, last) for two consecutive equal elements. Elements are compared using the ...
Definition adjacent_find.hpp:22
constexpr auto next(InputIt it, typename iterator_traits< InputIt >::difference_type n=1) -> InputIt
Return the nth successor of iterator it.
Definition next.hpp:14
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator== on type T....
Definition equal_to.hpp:14