search.pass.cpp 1.1 KB

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