1d835e592SMarshall Clow //===----------------------------------------------------------------------===//
2d835e592SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d835e592SMarshall Clow //
7d835e592SMarshall Clow //===----------------------------------------------------------------------===//
8d835e592SMarshall Clow
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10d835e592SMarshall Clow
11d835e592SMarshall Clow // <functional>
12d835e592SMarshall Clow
13d835e592SMarshall Clow // default searcher
14d835e592SMarshall Clow // template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
15d835e592SMarshall Clow // class default_searcher {
16d835e592SMarshall Clow // public:
17d835e592SMarshall Clow // default_searcher(_ForwardIterator __f, _ForwardIterator __l,
18d835e592SMarshall Clow // _BinaryPredicate __p = _BinaryPredicate())
19d835e592SMarshall Clow // : __first_(__f), __last_(__l), __pred_(__p) {}
20d835e592SMarshall Clow //
21d835e592SMarshall Clow // template <typename _ForwardIterator2>
22d835e592SMarshall Clow // pair<_ForwardIterator2, _ForwardIterator2>
23d835e592SMarshall Clow // operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const {
24d835e592SMarshall Clow // return std::search(__f, __l, __first_, __last_, __pred_);
25d835e592SMarshall Clow // }
26d835e592SMarshall Clow //
27d835e592SMarshall Clow // private:
28d835e592SMarshall Clow // _ForwardIterator __first_;
29d835e592SMarshall Clow // _ForwardIterator __last_;
30d835e592SMarshall Clow // _BinaryPredicate __pred_;
31d835e592SMarshall Clow // };
32d835e592SMarshall Clow
33d835e592SMarshall Clow
34d835e592SMarshall Clow #include <algorithm>
35d835e592SMarshall Clow #include <functional>
36d835e592SMarshall Clow #include <cassert>
37d835e592SMarshall Clow
387fc6a556SMarshall Clow #include "test_macros.h"
39d835e592SMarshall Clow #include "test_iterators.h"
40d835e592SMarshall Clow
41d835e592SMarshall Clow template <typename Iter1, typename Iter2>
42*7b00e9faSArthur O'Dwyer TEST_CONSTEXPR_CXX20
do_search(Iter1 b1,Iter1 e1,Iter2 b2,Iter2 e2,Iter1 result)43d835e592SMarshall Clow void do_search(Iter1 b1, Iter1 e1, Iter2 b2, Iter2 e2, Iter1 result) {
44d835e592SMarshall Clow std::default_searcher<Iter2> s{b2, e2};
45d835e592SMarshall Clow assert(result == std::search(b1, e1, s));
46d835e592SMarshall Clow }
47d835e592SMarshall Clow
48d835e592SMarshall Clow template <class Iter1, class Iter2>
49*7b00e9faSArthur O'Dwyer TEST_CONSTEXPR_CXX20
test()50*7b00e9faSArthur O'Dwyer bool test()
51d835e592SMarshall Clow {
52d835e592SMarshall Clow int ia[] = {0, 1, 2, 3, 4, 5};
53d835e592SMarshall Clow const unsigned sa = sizeof(ia)/sizeof(ia[0]);
54d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia), Iter1(ia));
55d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+1), Iter1(ia));
56d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa), Iter2(ia+1), Iter2(ia+2), Iter1(ia+1));
57d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa), Iter2(ia+2), Iter2(ia+2), Iter1(ia));
58d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa), Iter2(ia+2), Iter2(ia+3), Iter1(ia+2));
59d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa), Iter2(ia+2), Iter2(ia+3), Iter1(ia+2));
60d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia), Iter2(ia+2), Iter2(ia+3), Iter1(ia));
61d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa), Iter2(ia+sa-1), Iter2(ia+sa), Iter1(ia+sa-1));
62d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa), Iter2(ia+sa-3), Iter2(ia+sa), Iter1(ia+sa-3));
63d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), Iter1(ia));
64d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+sa-1), Iter2(ia), Iter2(ia+sa), Iter1(ia+sa-1));
65d835e592SMarshall Clow do_search(Iter1(ia), Iter1(ia+1), Iter2(ia), Iter2(ia+sa), Iter1(ia+1));
66d835e592SMarshall Clow int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4};
67d835e592SMarshall Clow const unsigned sb = sizeof(ib)/sizeof(ib[0]);
68d835e592SMarshall Clow int ic[] = {1};
69d835e592SMarshall Clow do_search(Iter1(ib), Iter1(ib+sb), Iter2(ic), Iter2(ic+1), Iter1(ib+1));
70d835e592SMarshall Clow int id[] = {1, 2};
71d835e592SMarshall Clow do_search(Iter1(ib), Iter1(ib+sb), Iter2(id), Iter2(id+2), Iter1(ib+1));
72d835e592SMarshall Clow int ie[] = {1, 2, 3};
73d835e592SMarshall Clow do_search(Iter1(ib), Iter1(ib+sb), Iter2(ie), Iter2(ie+3), Iter1(ib+4));
74d835e592SMarshall Clow int ig[] = {1, 2, 3, 4};
75d835e592SMarshall Clow do_search(Iter1(ib), Iter1(ib+sb), Iter2(ig), Iter2(ig+4), Iter1(ib+8));
76d835e592SMarshall Clow int ih[] = {0, 1, 1, 1, 1, 2, 3, 0, 1, 2, 3, 4};
77d835e592SMarshall Clow const unsigned sh = sizeof(ih)/sizeof(ih[0]);
78d835e592SMarshall Clow int ii[] = {1, 1, 2};
79d835e592SMarshall Clow do_search(Iter1(ih), Iter1(ih+sh), Iter2(ii), Iter2(ii+3), Iter1(ih+3));
80d835e592SMarshall Clow int ij[] = {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
81d835e592SMarshall Clow const unsigned sj = sizeof(ij)/sizeof(ij[0]);
82d835e592SMarshall Clow int ik[] = {0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
83d835e592SMarshall Clow const unsigned sk = sizeof(ik)/sizeof(ik[0]);
84d835e592SMarshall Clow do_search(Iter1(ij), Iter1(ij+sj), Iter2(ik), Iter2(ik+sk), Iter1(ij+6));
85*7b00e9faSArthur O'Dwyer
86*7b00e9faSArthur O'Dwyer return true;
87d835e592SMarshall Clow }
88d835e592SMarshall Clow
main(int,char **)892df59c50SJF Bastien int main(int, char**) {
90d835e592SMarshall Clow test<forward_iterator<const int*>, forward_iterator<const int*> >();
91d835e592SMarshall Clow test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
92d835e592SMarshall Clow test<forward_iterator<const int*>, random_access_iterator<const int*> >();
93d835e592SMarshall Clow test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
94d835e592SMarshall Clow test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
95d835e592SMarshall Clow test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
96d835e592SMarshall Clow test<random_access_iterator<const int*>, forward_iterator<const int*> >();
97d835e592SMarshall Clow test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
98d835e592SMarshall Clow test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
992df59c50SJF Bastien
100*7b00e9faSArthur O'Dwyer #if TEST_STD_VER >= 20
101*7b00e9faSArthur O'Dwyer static_assert(test<forward_iterator<const int*>, forward_iterator<const int*>>());
102*7b00e9faSArthur O'Dwyer static_assert(test<forward_iterator<const int*>, bidirectional_iterator<const int*>>());
103*7b00e9faSArthur O'Dwyer static_assert(test<forward_iterator<const int*>, random_access_iterator<const int*>>());
104*7b00e9faSArthur O'Dwyer static_assert(test<bidirectional_iterator<const int*>, forward_iterator<const int*>>());
105*7b00e9faSArthur O'Dwyer static_assert(test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>>());
106*7b00e9faSArthur O'Dwyer static_assert(test<bidirectional_iterator<const int*>, random_access_iterator<const int*>>());
107*7b00e9faSArthur O'Dwyer static_assert(test<random_access_iterator<const int*>, forward_iterator<const int*>>());
108*7b00e9faSArthur O'Dwyer static_assert(test<random_access_iterator<const int*>, bidirectional_iterator<const int*>>());
109*7b00e9faSArthur O'Dwyer static_assert(test<random_access_iterator<const int*>, random_access_iterator<const int*>>());
110*7b00e9faSArthur O'Dwyer #endif
111*7b00e9faSArthur O'Dwyer
1122df59c50SJF Bastien return 0;
113d835e592SMarshall Clow }
114