tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
default_searcher.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_FUNCTIONAL_DEFAULT_SEARCHER_HPP
5#define TETL_FUNCTIONAL_DEFAULT_SEARCHER_HPP
6
7#include <etl/_algorithm/search.hpp>
8#include <etl/_functional/equal_to.hpp>
9#include <etl/_iterator/distance.hpp>
10#include <etl/_iterator/next.hpp>
11#include <etl/_utility/forward.hpp>
12#include <etl/_utility/pair.hpp>
13
14namespace etl {
15
16/// \brief Default searcher. A class suitable for use with Searcher overload of
17/// etl::search that delegates the search operation to the pre-C++17 standard
18/// library's etl::search.
19template <typename ForwardIter, typename Predicate = equal_to<>>
21 constexpr default_searcher(ForwardIter f, ForwardIter l, Predicate p = Predicate())
22 : _first(f)
23 , _last(l)
24 , _predicate(p)
25 {
26 }
27
28 template <typename ForwardIter2>
29 constexpr auto operator()(ForwardIter2 f, ForwardIter2 l) const -> etl::pair<ForwardIter2, ForwardIter2>
30 {
31 if (auto i = etl::search(f, l, _first, _last, _predicate); i != l) {
32 auto j = etl::next(i, etl::distance(_first, _last));
33 return etl::pair<ForwardIter2, ForwardIter2>{i, j};
34 }
35
36 return etl::pair<ForwardIter2, ForwardIter2>{l, l};
37 }
38
39private:
40 ForwardIter _first;
41 ForwardIter _last;
42 Predicate _predicate;
43};
44
45} // namespace etl
46
47#endif // TETL_FUNCTIONAL_DEFAULT_SEARCHER_HPP
Definition adjacent_find.hpp:9
Default searcher. A class suitable for use with Searcher overload of etl::search that delegates the s...
Definition default_searcher.hpp:20
constexpr auto operator()(ForwardIter2 f, ForwardIter2 l) const -> etl::pair< ForwardIter2, ForwardIter2 >
Definition default_searcher.hpp:29
constexpr default_searcher(ForwardIter f, ForwardIter l, Predicate p=Predicate())
Definition default_searcher.hpp:21
Function object for performing comparisons. Unless specialised, invokes operator== on type T....
Definition equal_to.hpp:15
etl::pair is a class template that provides a way to store two heterogeneous objects as a single unit...
Definition pair.hpp:37