xref: /llvm-project/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp (revision 4159db7698d3d6aa5e0f2d920be3847716b05800)
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <algorithm>
11 
12 // template<InputIterator Iter, Predicate<auto, Iter::value_type> Pred>
13 //   requires CopyConstructible<Pred>
14 //   Iter
15 //   find_if(Iter first, Iter last, Pred pred);
16 
17 #include <algorithm>
18 #include <functional>
19 #include <cassert>
20 
21 #include "test_iterators.h"
22 
23 struct eq {
24     eq (int val) : v(val) {}
25     bool operator () (int v2) const { return v == v2; }
26     int v;
27     };
28 
29 int main()
30 {
31     int ia[] = {0, 1, 2, 3, 4, 5};
32     const unsigned s = sizeof(ia)/sizeof(ia[0]);
33     input_iterator<const int*> r = std::find_if(input_iterator<const int*>(ia),
34                                                 input_iterator<const int*>(ia+s),
35                                                 eq(3));
36     assert(*r == 3);
37     r = std::find_if(input_iterator<const int*>(ia),
38                      input_iterator<const int*>(ia+s),
39                      eq(10));
40     assert(r == input_iterator<const int*>(ia+s));
41 }
42