1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <algorithm>
10 
11 // template<InputIterator Iter1, ForwardIterator Iter2,
12 //          Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
13 //   requires CopyConstructible<Pred>
14 //   constexpr Iter1  // constexpr after C++17
15 //   find_first_of(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Pred pred);
16 
17 #include <algorithm>
18 #include <functional>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 #include "test_iterators.h"
23 
24 #if TEST_STD_VER > 17
test_constexpr()25 constexpr bool test_constexpr() {
26     int ia[] = {1, 2, 3};
27     int ib[] = {7, 8, 9};
28     int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3};
29     typedef forward_iterator<int*>       FI;
30     typedef bidirectional_iterator<int*> BI;
31     typedef random_access_iterator<int*> RI;
32     std::equal_to<int> eq{};
33     return    (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ia)), FI(std::end(ia)), eq) == FI(ic+1))
34            && (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ib)), FI(std::end(ib)), eq) == FI(std::end(ic)))
35            && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ia)), BI(std::end(ia)), eq) == BI(ic+1))
36            && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ib)), BI(std::end(ib)), eq) == BI(std::end(ic)))
37            && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ia)), RI(std::end(ia)), eq) == RI(ic+1))
38            && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ib)), RI(std::end(ib)), eq) == RI(std::end(ic)))
39            ;
40     }
41 #endif
42 
main(int,char **)43 int main(int, char**)
44 {
45     int ia[] = {0, 1, 2, 3, 0, 1, 2, 3};
46     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
47     int ib[] = {1, 3, 5, 7};
48     const unsigned sb = sizeof(ib)/sizeof(ib[0]);
49     assert(std::find_first_of(cpp17_input_iterator<const int*>(ia),
50                               cpp17_input_iterator<const int*>(ia + sa),
51                               forward_iterator<const int*>(ib),
52                               forward_iterator<const int*>(ib + sb),
53                               std::equal_to<int>()) ==
54                               cpp17_input_iterator<const int*>(ia+1));
55     int ic[] = {7};
56     assert(std::find_first_of(cpp17_input_iterator<const int*>(ia),
57                               cpp17_input_iterator<const int*>(ia + sa),
58                               forward_iterator<const int*>(ic),
59                               forward_iterator<const int*>(ic + 1),
60                               std::equal_to<int>()) ==
61                               cpp17_input_iterator<const int*>(ia+sa));
62     assert(std::find_first_of(cpp17_input_iterator<const int*>(ia),
63                               cpp17_input_iterator<const int*>(ia + sa),
64                               forward_iterator<const int*>(ic),
65                               forward_iterator<const int*>(ic),
66                               std::equal_to<int>()) ==
67                               cpp17_input_iterator<const int*>(ia+sa));
68     assert(std::find_first_of(cpp17_input_iterator<const int*>(ia),
69                               cpp17_input_iterator<const int*>(ia),
70                               forward_iterator<const int*>(ic),
71                               forward_iterator<const int*>(ic+1),
72                               std::equal_to<int>()) ==
73                               cpp17_input_iterator<const int*>(ia));
74 
75 #if TEST_STD_VER > 17
76     static_assert(test_constexpr());
77 #endif
78 
79   return 0;
80 }
81