blob: e27f0e43b18baef249c832fdaa2106c57df3fda5 [file] [log] [blame]
Marshall Clow166dadb2015-07-20 15:40:27 +00001//===----------------------------------------------------------------------===//
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//
Dan Albert1d4a1ed2016-05-25 22:36:09 -070016// returns searcher.operator(first, last)
Marshall Clow166dadb2015-07-20 15:40:27 +000017//
18
19#include <experimental/algorithm>
20#include <cassert>
21
22#include "test_iterators.h"
23
24int searcher_called = 0;
25
26struct MySearcher {
27 template <typename Iterator>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070028 Iterator operator() ( Iterator b, Iterator /*e*/) const
Marshall Clow166dadb2015-07-20 15:40:27 +000029 {
30 ++searcher_called;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070031 return b;
Marshall Clow166dadb2015-07-20 15:40:27 +000032 }
33};
34
35
36int main() {
37 typedef int * RI;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070038 static_assert(std::is_same<RI, decltype(std::experimental::search(RI(), RI(), MySearcher()))>::value, "" );
Marshall Clow166dadb2015-07-20 15:40:27 +000039
Dan Albert1d4a1ed2016-05-25 22:36:09 -070040 RI it{nullptr};
Marshall Clow166dadb2015-07-20 15:40:27 +000041 assert(it == std::experimental::search(it, it, MySearcher()));
42 assert(searcher_called == 1);
43}