Marshall Clow | 166dadb | 2015-07-20 15:40:27 +0000 | [diff] [blame] | 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 | // |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 16 | // returns searcher.operator(first, last) |
Marshall Clow | 166dadb | 2015-07-20 15:40:27 +0000 | [diff] [blame] | 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> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 28 | Iterator operator() ( Iterator b, Iterator /*e*/) const |
Marshall Clow | 166dadb | 2015-07-20 15:40:27 +0000 | [diff] [blame] | 29 | { |
| 30 | ++searcher_called; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 31 | return b; |
Marshall Clow | 166dadb | 2015-07-20 15:40:27 +0000 | [diff] [blame] | 32 | } |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | int main() { |
| 37 | typedef int * RI; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 38 | static_assert(std::is_same<RI, decltype(std::experimental::search(RI(), RI(), MySearcher()))>::value, "" ); |
Marshall Clow | 166dadb | 2015-07-20 15:40:27 +0000 | [diff] [blame] | 39 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 40 | RI it{nullptr}; |
Marshall Clow | 166dadb | 2015-07-20 15:40:27 +0000 | [diff] [blame] | 41 | assert(it == std::experimental::search(it, it, MySearcher())); |
| 42 | assert(searcher_called == 1); |
| 43 | } |