diff options
Diffstat (limited to 'test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp')
| -rw-r--r-- | test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp b/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp index e5c2dd29d11f1..d483800c20912 100644 --- a/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp @@ -11,14 +11,52 @@ // template<ForwardIterator Iter1, ForwardIterator Iter2> // requires HasEqualTo<Iter1::value_type, Iter2::value_type> -// Iter1 +// constexpr Iter1 // constexpr after C++17 // search(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2); +// +// template<class ForwardIterator, class Searcher> +// ForwardIterator search(ForwardIterator first, ForwardIterator last, +// const Searcher& searcher); // C++17 #include <algorithm> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" +struct MySearcherC { + template <typename Iterator> + std::pair<Iterator, Iterator> + TEST_CONSTEXPR operator() (Iterator b, Iterator e) const + { + return std::make_pair(b, e); + } +}; + +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + int ia[] = {0, 1, 2, 3}; + int ib[] = {0, 1, 5, 3}; + int ic[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4}; + return (std::search(std::begin(ic), std::end(ic), std::begin(ia), std::end(ia)) == ic+3) + && (std::search(std::begin(ic), std::end(ic), std::begin(ib), std::end(ib)) == std::end(ic)) + && (std::search(std::begin(ic), std::end(ic), MySearcherC()) == std::begin(ic)) + ; + } +#endif + +int searcher_called = 0; + +struct MySearcher { + template <typename Iterator> + std::pair<Iterator, Iterator> + operator() (Iterator b, Iterator e) const + { + ++searcher_called; + return std::make_pair(b, e); + } +}; + template <class Iter1, class Iter2> void test() @@ -69,4 +107,19 @@ int main() test<random_access_iterator<const int*>, forward_iterator<const int*> >(); test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >(); test<random_access_iterator<const int*>, random_access_iterator<const int*> >(); + +#if TEST_STD_VER > 14 +{ + typedef int * RI; + static_assert((std::is_same<RI, decltype(std::search(RI(), RI(), MySearcher()))>::value), "" ); + + RI it(nullptr); + assert(it == std::search(it, it, MySearcher())); + assert(searcher_called == 1); +} +#endif + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } |
