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 // UNSUPPORTED: c++98, c++03, c++11
10 
11 // <algorithm>
12 
13 //   template<class ForwardIterator, class Searcher>
14 //   ForwardIterator search(ForwardIterator first, ForwardIterator last,
15 //                          const Searcher& searcher);
16 //
17 //      returns searcher.operator(first, last).first
18 //
19 
20 #include <experimental/algorithm>
21 #include <cassert>
22 
23 #include "test_iterators.h"
24 
25 int searcher_called = 0;
26 
27 struct MySearcher {
28     template <typename Iterator>
29     std::pair<Iterator, Iterator>
30     operator() (Iterator b, Iterator e) const
31     {
32         ++searcher_called;
33         return std::make_pair(b, e);
34     }
35 };
36 
37 
38 int main(int, char**) {
39     typedef int * RI;
40     static_assert((std::is_same<RI, decltype(std::experimental::search(RI(), RI(), MySearcher()))>::value), "" );
41 
42     RI it(nullptr);
43     assert(it == std::experimental::search(it, it, MySearcher()));
44     assert(searcher_called == 1);
45 
46   return 0;
47 }
48