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//===----------------------------------------------------------------------===//
8
9// <algorithm>
10
11// template<InputIterator Iter, Predicate<auto, Iter::value_type> Pred>
12// requires CopyConstructible<Pred>
13// constexpr Iter // constexpr after C++17
14// find_if_not(Iter first, Iter last, Pred pred);
15
16#include <algorithm>
17#include <functional>
18#include <cassert>
19
20#include "test_macros.h"
21#include "test_iterators.h"
22
23struct DifferentFrom {
24 int v;
25 TEST_CONSTEXPR DifferentFrom(int val) : v(val) {}
26 TEST_CONSTEXPR bool operator()(int other) const { return v != other; }
27};
28
29template <class Iter>
30TEST_CONSTEXPR_CXX17 void test_iter() {
31 int range[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
32
33 // We don't find what we're looking for in the range
34 {
35 {
36 Iter result = std::find_if_not(Iter(range), Iter(range), DifferentFrom(0));
37 assert(result == Iter(range));
38 }
39 {
40 Iter result = std::find_if_not(Iter(range), Iter(std::end(arr&: range)), DifferentFrom(999));
41 assert(result == Iter(std::end(range)));
42 }
43 }
44
45 // Tests with sub-ranges of various sizes
46 for (int size = 1; size != 10; ++size) {
47 for (int i = 0; i != size - 1; ++i) {
48 Iter result = std::find_if_not(Iter(range), Iter(range + size), DifferentFrom(i));
49 assert(result == Iter(range + i));
50 }
51 }
52}
53
54TEST_CONSTEXPR_CXX17 bool test() {
55 test_iter<cpp17_input_iterator<int*> >();
56 test_iter<forward_iterator<int*> >();
57 test_iter<bidirectional_iterator<int*> >();
58 test_iter<random_access_iterator<int*> >();
59 return true;
60}
61
62int main(int, char**) {
63 test();
64#if TEST_STD_VER >= 20
65 static_assert(test());
66#endif
67
68 return 0;
69}
70

source code of libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp