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++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_macros.h" 24 #include "test_iterators.h" 25 26 int searcher_called = 0; 27 28 struct MySearcher { 29 template <typename Iterator> 30 std::pair<Iterator, Iterator> 31 operator() (Iterator b, Iterator e) const 32 { 33 ++searcher_called; 34 return std::make_pair(b, e); 35 } 36 }; 37 38 39 int main(int, char**) { 40 typedef int * RI; 41 static_assert((std::is_same<RI, decltype(std::experimental::search(RI(), RI(), MySearcher()))>::value), "" ); 42 43 RI it(nullptr); 44 assert(it == std::experimental::search(it, it, MySearcher())); 45 assert(searcher_called == 1); 46 47 return 0; 48 } 49