Sane C++ Libraries
C++ Platform Abstraction Libraries
AlgorithmFind.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Foundation/Assert.h"
5
6namespace SC
7{
9namespace Algorithms
10{
11
14
22template <typename ForwardIterator, typename UnaryPredicate>
23constexpr ForwardIterator findIf(ForwardIterator first, ForwardIterator last, UnaryPredicate&& predicate)
24{
25 SC_ASSERT_DEBUG(first <= last);
26 for (auto it = first; it != last; ++it)
27 {
28 if (predicate(*it))
29 {
30 return it;
31 }
32 }
33 return last;
34}
35
37
38} // namespace Algorithms
39} // namespace SC
constexpr ForwardIterator findIf(ForwardIterator first, ForwardIterator last, UnaryPredicate &&predicate)
Find item satisfying the given predicate.
Definition: AlgorithmFind.h:23
#define SC_ASSERT_DEBUG(e)
Assert expression e to be true.
Definition: Assert.h:82