53 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <algorithm>10 11// template<ForwardIterator Iter>12// requires EqualityComparable<Iter::value_type>13// constexpr Iter // constexpr after C++1714// adjacent_find(Iter first, Iter last);15 16#include <algorithm>17#include <cassert>18 19#include "test_macros.h"20#include "test_iterators.h"21 22#if TEST_STD_VER > 1723TEST_CONSTEXPR bool test_constexpr() {24 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};25 int ib[] = {0, 1, 2, 7, 0, 1, 2, 3};26 27 return (std::adjacent_find(std::begin(ia), std::end(ia)) == ia+2)28 && (std::adjacent_find(std::begin(ib), std::end(ib)) == std::end(ib))29 ;30 }31#endif32 33int main(int, char**)34{35 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};36 const unsigned sa = sizeof(ia)/sizeof(ia[0]);37 assert(std::adjacent_find(forward_iterator<const int*>(ia),38 forward_iterator<const int*>(ia + sa)) ==39 forward_iterator<const int*>(ia+2));40 assert(std::adjacent_find(forward_iterator<const int*>(ia),41 forward_iterator<const int*>(ia)) ==42 forward_iterator<const int*>(ia));43 assert(std::adjacent_find(forward_iterator<const int*>(ia+3),44 forward_iterator<const int*>(ia + sa)) ==45 forward_iterator<const int*>(ia+sa));46 47#if TEST_STD_VER > 1748 static_assert(test_constexpr());49#endif50 51 return 0;52}53