tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
find_first_of.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_FIND_FIRST_OF_HPP
5#define TETL_ALGORITHM_FIND_FIRST_OF_HPP
6
7#include <etl/_functional/equal_to.hpp>
8
9namespace etl {
10
11/// Searches the range `[first, last)` for any of the elements in the
12/// range [sFirst, sLast). Elements are compared using the given binary
13/// predicate pred.
14///
15/// \param first The range of elements to examine.
16/// \param last The range of elements to examine.
17/// \param sFirst The range of elements to search for.
18/// \param sLast The range of elements to search for.
19/// \param pred Predicate which returns ​true if the elements should be
20/// treated as equal.
21///
22/// https://en.cppreference.com/w/cpp/algorithm/find_first_of
23///
24/// \ingroup algorithm
25template <typename InputIt, typename ForwardIt, typename Predicate>
26[[nodiscard]] constexpr auto
27find_first_of(InputIt first, InputIt last, ForwardIt sFirst, ForwardIt sLast, Predicate pred) -> InputIt
28{
29 for (; first != last; ++first) {
30 for (auto it = sFirst; it != sLast; ++it) {
31 if (pred(*first, *it)) {
32 return first;
33 }
34 }
35 }
36
37 return last;
38}
39
40/// \brief Searches the range `[first, last)` for any of the elements in the
41/// range [sFirst, sLast).
42///
43/// \param first The range of elements to examine.
44/// \param last The range of elements to examine.
45/// \param sFirst The range of elements to search for.
46/// \param sLast The range of elements to search for.
47///
48/// https://en.cppreference.com/w/cpp/algorithm/find_first_of
49///
50/// \ingroup algorithm
51template <typename InputIt, typename ForwardIt>
52[[nodiscard]] constexpr auto find_first_of(InputIt first, InputIt last, ForwardIt sFirst, ForwardIt sLast) -> InputIt
53{
54 return etl::find_first_of(first, last, sFirst, sLast, etl::equal_to());
55}
56
57} // namespace etl
58
59#endif // TETL_ALGORITHM_FIND_FIRST_OF_HPP
constexpr auto find_first_of(InputIt first, InputIt last, ForwardIt sFirst, ForwardIt sLast) -> InputIt
Searches the range [first, last) for any of the elements in the range [sFirst, sLast).
Definition find_first_of.hpp:52
constexpr auto find_first_of(InputIt first, InputIt last, ForwardIt sFirst, ForwardIt sLast, Predicate pred) -> InputIt
Searches the range [first, last) for any of the elements in the range [sFirst, sLast)....
Definition find_first_of.hpp:27
Definition adjacent_find.hpp:9
Function object for performing comparisons. Unless specialised, invokes operator== on type T....
Definition equal_to.hpp:15