]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp
Vendor import of libc++ trunk r338150:
[FreeBSD/FreeBSD.git] / test / std / algorithms / alg.nonmodifying / alg.find.first.of / find_first_of.pass.cpp
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 Iter1, ForwardIterator Iter2>
13 //   requires HasEqualTo<Iter1::value_type, Iter2::value_type>
14 //   constexpr Iter1  // constexpr after C++17
15 //   find_first_of(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
16
17 #include <algorithm>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "test_iterators.h"
22
23 #if TEST_STD_VER > 17
24 TEST_CONSTEXPR bool test_constexpr() {
25     int ia[] = {1, 2, 3};
26     int ib[] = {7, 8, 9};
27     int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3};
28     typedef forward_iterator<int*>       FI;
29     typedef bidirectional_iterator<int*> BI;
30     typedef random_access_iterator<int*> RI;
31
32     return    (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ia)), FI(std::end(ia))) == FI(ic+1))
33            && (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ib)), FI(std::end(ib))) == FI(std::end(ic)))
34            && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ia)), BI(std::end(ia))) == BI(ic+1))
35            && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ib)), BI(std::end(ib))) == BI(std::end(ic)))
36            && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ia)), RI(std::end(ia))) == RI(ic+1))
37            && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ib)), RI(std::end(ib))) == RI(std::end(ic)))
38            ;
39     }
40 #endif
41
42 int main()
43 {
44     int ia[] = {0, 1, 2, 3, 0, 1, 2, 3};
45     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
46     int ib[] = {1, 3, 5, 7};
47     const unsigned sb = sizeof(ib)/sizeof(ib[0]);
48     assert(std::find_first_of(input_iterator<const int*>(ia),
49                               input_iterator<const int*>(ia + sa),
50                               forward_iterator<const int*>(ib),
51                               forward_iterator<const int*>(ib + sb)) ==
52                               input_iterator<const int*>(ia+1));
53     int ic[] = {7};
54     assert(std::find_first_of(input_iterator<const int*>(ia),
55                               input_iterator<const int*>(ia + sa),
56                               forward_iterator<const int*>(ic),
57                               forward_iterator<const int*>(ic + 1)) ==
58                               input_iterator<const int*>(ia+sa));
59     assert(std::find_first_of(input_iterator<const int*>(ia),
60                               input_iterator<const int*>(ia + sa),
61                               forward_iterator<const int*>(ic),
62                               forward_iterator<const int*>(ic)) ==
63                               input_iterator<const int*>(ia+sa));
64     assert(std::find_first_of(input_iterator<const int*>(ia),
65                               input_iterator<const int*>(ia),
66                               forward_iterator<const int*>(ic),
67                               forward_iterator<const int*>(ic+1)) ==
68                               input_iterator<const int*>(ia));
69
70 #if TEST_STD_VER > 17
71     static_assert(test_constexpr());
72 #endif
73 }