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