search.pass.cpp 1.2 KB

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