tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
search.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_SEARCH_HPP
4#define TETL_ALGORITHM_SEARCH_HPP
5
7
8namespace etl {
9
12
23template <typename FwdIt1, typename FwdIt2, typename Predicate>
24[[nodiscard]] constexpr auto search(FwdIt1 first, FwdIt1 last, FwdIt2 sFirst, FwdIt2 sLast, Predicate pred) -> FwdIt1
25{
26 for (;; ++first) {
27 auto it = first;
28 for (auto sIt = sFirst;; ++it, (void)++sIt) {
29 if (sIt == sLast) {
30 return first;
31 }
32 if (it == last) {
33 return last;
34 }
35 if (not pred(*it, *sIt)) {
36 break;
37 }
38 }
39 }
40}
41
42template <typename FwdIt1, typename FwdIt2>
43[[nodiscard]] constexpr auto search(FwdIt1 first, FwdIt1 last, FwdIt2 sFirst, FwdIt2 sLast) -> FwdIt1
44{
45 return etl::search(first, last, sFirst, sLast, etl::equal_to());
46}
47
48template <typename FwdIt, typename Searcher>
49[[nodiscard]] constexpr auto search(FwdIt first, FwdIt last, Searcher const& searcher) -> FwdIt
50{
51 return searcher(first, last).first;
52}
53
55
56} // namespace etl
57
58#endif // TETL_ALGORITHM_SEARCH_HPP
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