tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
find_if.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_ALGORITHM_FIND_IF_HPP
5#define TETL_ALGORITHM_FIND_IF_HPP
6
7namespace etl {
8
9/// \brief Searches for an element for which predicate p returns true
10///
11/// \param first The range of elements to examine.
12/// \param last The range of elements to examine.
13/// \param pred Unary predicate which returns ​true for the required element.
14///
15/// https://en.cppreference.com/w/cpp/algorithm/find
16///
17/// \ingroup algorithm
18template <typename InputIt, typename Predicate>
19[[nodiscard]] constexpr auto find_if(InputIt first, InputIt last, Predicate pred) noexcept -> InputIt
20{
21 for (; first != last; ++first) {
22 if (pred(*first)) {
23 return first;
24 }
25 }
26 return last;
27}
28
29} // namespace etl
30
31#endif // TETL_ALGORITHM_FIND_IF_HPP
constexpr auto find_if(InputIt first, InputIt last, Predicate pred) noexcept -> InputIt
Searches for an element for which predicate p returns true.
Definition find_if.hpp:19
Definition adjacent_find.hpp:9