tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
find_end.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_FIND_END_HPP
4#define TETL_ALGORITHM_FIND_END_HPP
5
8
9namespace etl {
10
23template <typename ForwardIt1, typename ForwardIt2, typename Predicate>
24[[nodiscard]] constexpr auto
25find_end(ForwardIt1 first, ForwardIt1 last, ForwardIt2 sFirst, ForwardIt2 sLast, Predicate p) -> ForwardIt1
26{
27 if (sFirst == sLast) {
28 return last;
29 }
30 auto result = last;
31 while (true) {
32 auto newResult = etl::search(first, last, sFirst, sLast, p);
33 if (newResult == last) {
34 break;
35 }
36 result = newResult;
37 first = result;
38 ++first;
39 }
40 return result;
41}
42
44template <typename ForwardIt1, typename ForwardIt2>
45[[nodiscard]] constexpr auto find_end(ForwardIt1 first, ForwardIt1 last, ForwardIt2 sFirst, ForwardIt2 sLast)
46 -> ForwardIt1
47{
48 return etl::find_end(first, last, sFirst, sLast, etl::equal_to());
49}
50
51} // namespace etl
52
53#endif // TETL_ALGORITHM_FIND_END_HPP
constexpr auto find_end(ForwardIt1 first, ForwardIt1 last, ForwardIt2 sFirst, ForwardIt2 sLast, Predicate p) -> ForwardIt1
Searches for the last occurrence of the sequence [sFirst, sLast) in the range [first,...
Definition find_end.hpp:25
constexpr auto search(FwdIt1 first, FwdIt1 last, FwdIt2 sFirst, FwdIt2 sLast, Predicate pred) -> FwdIt1
Searches for the first occurrence of the sequence of elements [sFirst, sLast) in the range [first,...
Definition search.hpp:24
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator== on type T....
Definition equal_to.hpp:14