adjacent_find.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2014-present
  4. //
  5. // Use, modification and distribution is subject to the
  6. // Boost Software License, Version 1.0. (See accompanying
  7. // file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Project home: https://github.com/ericniebler/range-v3
  11. #include <range/v3/core.hpp>
  12. #include <range/v3/algorithm/adjacent_find.hpp>
  13. #include "../array.hpp"
  14. #include "../simple_test.hpp"
  15. int main()
  16. {
  17. int v1[] = { 0, 2, 2, 4, 6 };
  18. CHECK(ranges::adjacent_find(ranges::begin(v1), ranges::end(v1)) == &v1[1]);
  19. CHECK(ranges::adjacent_find(v1) == &v1[1]);
  20. std::pair<int, int> v2[] = {{0, 0}, {0, 2}, {0, 2}, {0, 4}, {0, 6}};
  21. CHECK(ranges::adjacent_find(ranges::begin(v2), ranges::end(v2),
  22. ranges::equal_to{}, &std::pair<int, int>::second) == &v2[1]);
  23. CHECK(ranges::adjacent_find(v2, ranges::equal_to{}, &std::pair<int, int>::second) == &v2[1]);
  24. static_assert(std::is_same<std::pair<int,int>*,
  25. decltype(ranges::adjacent_find(v2, ranges::equal_to{},
  26. &std::pair<int, int>::second))>::value, "");
  27. {
  28. using namespace ranges;
  29. constexpr auto a1 = test::array<int, 5>{{0, 2, 2, 4, 6}};
  30. STATIC_CHECK(adjacent_find(begin(a1), end(a1)) == (begin(a1) + 1));
  31. STATIC_CHECK(adjacent_find(a1) == (begin(a1) + 1));
  32. constexpr std::pair<int, int> a2[] = {{0, 0}, {0, 2}, {0, 2}, {0, 4}, {0, 6}};
  33. STATIC_CHECK(adjacent_find(a2, ranges::equal_to{}) == (begin(a2) + 1));
  34. }
  35. return test_result();
  36. }