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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
15 // template<class ExecutionPolicy, class ForwardIterator, class T>
16 // typename iterator_traits<ForwardIterator>::difference_type
17 // count(ExecutionPolicy&& exec,
18 // ForwardIterator first, ForwardIterator last, const T& value);
25 #include "test_macros.h"
26 #include "test_execution_policies.h"
27 #include "test_iterators.h"
29 EXECUTION_POLICY_SFINAE_TEST(count
);
31 static_assert(sfinae_test_count
<int, int*, int*, bool (*)(int)>);
32 static_assert(!sfinae_test_count
<std::execution::parallel_policy
, int*, int*, int>);
36 template <class Policy
>
37 void operator()(Policy
&& policy
) {
39 int a
[] = {1, 2, 3, 4, 5};
40 decltype(auto) ret
= std::count(policy
, std::begin(a
), std::end(a
), 3);
41 static_assert(std::is_same_v
<decltype(ret
), typename
std::iterator_traits
<Iter
>::difference_type
>);
45 { // test that an empty range works
47 decltype(auto) ret
= std::count(policy
, std::begin(a
), std::end(a
), 3);
48 static_assert(std::is_same_v
<decltype(ret
), typename
std::iterator_traits
<Iter
>::difference_type
>);
52 { // test that a single-element range works
54 decltype(auto) ret
= std::count(policy
, std::begin(a
), std::end(a
), 1);
55 static_assert(std::is_same_v
<decltype(ret
), typename
std::iterator_traits
<Iter
>::difference_type
>);
59 { // test that a two-element range works
61 decltype(auto) ret
= std::count(policy
, std::begin(a
), std::end(a
), 3);
62 static_assert(std::is_same_v
<decltype(ret
), typename
std::iterator_traits
<Iter
>::difference_type
>);
66 { // test that a three-element range works
68 decltype(auto) ret
= std::count(policy
, std::begin(a
), std::end(a
), 3);
69 static_assert(std::is_same_v
<decltype(ret
), typename
std::iterator_traits
<Iter
>::difference_type
>);
73 { // test that a large range works
74 std::vector
<int> a(100, 2);
75 decltype(auto) ret
= std::count(policy
, std::begin(a
), std::end(a
), 2);
76 static_assert(std::is_same_v
<decltype(ret
), typename
std::iterator_traits
<Iter
>::difference_type
>);
82 int main(int, char**) {
83 types::for_each(types::forward_iterator_list
<int*>{}, TestIteratorWithPolicies
<Test
>{});