1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template<InputIterator Iter, Predicate<auto, Iter::value_type> Pred>
12 // requires CopyConstructible<Pred>
13 // constexpr Iter::difference_type // constexpr after C++17
14 // count_if(Iter first, Iter last, Pred pred);
20 #include "test_macros.h"
21 #include "test_iterators.h"
24 TEST_CONSTEXPR
eq (int val
) : v(val
) {}
25 TEST_CONSTEXPR
bool operator () (int v2
) const { return v
== v2
; }
30 TEST_CONSTEXPR
bool test_constexpr() {
31 int ia
[] = {0, 1, 2, 2, 0, 1, 2, 3};
32 int ib
[] = {1, 2, 3, 4, 5, 6};
33 return (std::count_if(std::begin(ia
), std::end(ia
), eq(2)) == 3)
34 && (std::count_if(std::begin(ib
), std::end(ib
), eq(9)) == 0)
41 int ia
[] = {0, 1, 2, 2, 0, 1, 2, 3};
42 const unsigned sa
= sizeof(ia
)/sizeof(ia
[0]);
43 assert(std::count_if(input_iterator
<const int*>(ia
),
44 input_iterator
<const int*>(ia
+ sa
),
46 assert(std::count_if(input_iterator
<const int*>(ia
),
47 input_iterator
<const int*>(ia
+ sa
),
49 assert(std::count_if(input_iterator
<const int*>(ia
),
50 input_iterator
<const int*>(ia
),
54 static_assert(test_constexpr());