Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / algorithms / alg.nonmodifying / alg.adjacent.find / adjacent_find_pred.pass.cpp
blobc80bc9fff83b64f42f8cf404679f5e4e231c01d9
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <algorithm>
11 // template<ForwardIterator Iter, EquivalenceRelation<auto, Iter::value_type> Pred>
12 // requires CopyConstructible<Pred>
13 // constexpr Iter // constexpr after C++17
14 // adjacent_find(Iter first, Iter last, Pred pred);
16 #include <algorithm>
17 #include <functional>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "test_iterators.h"
24 #if TEST_STD_VER > 17
25 TEST_CONSTEXPR bool eq (int a, int b) { return a == b; }
27 TEST_CONSTEXPR bool test_constexpr() {
28 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
29 int ib[] = {0, 1, 2, 7, 0, 1, 2, 3};
31 return (std::adjacent_find(std::begin(ia), std::end(ia), eq) == ia+2)
32 && (std::adjacent_find(std::begin(ib), std::end(ib), eq) == std::end(ib))
35 #endif
37 int main(int, char**)
39 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
40 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
41 assert(std::adjacent_find(forward_iterator<const int*>(ia),
42 forward_iterator<const int*>(ia + sa),
43 std::equal_to<int>()) ==
44 forward_iterator<const int*>(ia+2));
45 assert(std::adjacent_find(forward_iterator<const int*>(ia),
46 forward_iterator<const int*>(ia),
47 std::equal_to<int>()) ==
48 forward_iterator<const int*>(ia));
49 assert(std::adjacent_find(forward_iterator<const int*>(ia+3),
50 forward_iterator<const int*>(ia + sa),
51 std::equal_to<int>()) ==
52 forward_iterator<const int*>(ia+sa));
54 #if TEST_STD_VER > 17
55 static_assert(test_constexpr());
56 #endif
58 return 0;