Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / algorithms / alg.nonmodifying / alg.count / pstl.count.pass.cpp
blobf00861f66bfe90bea05db2073dbde17d1cfdbd2c
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 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
13 // <algorithm>
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);
20 #include <algorithm>
21 #include <array>
22 #include <cassert>
23 #include <vector>
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>);
34 template <class Iter>
35 struct Test {
36 template <class Policy>
37 void operator()(Policy&& policy) {
38 { // simple test
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>);
42 assert(ret == 1);
45 { // test that an empty range works
46 std::array<int, 0> a;
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>);
49 assert(ret == 0);
52 { // test that a single-element range works
53 int a[] = {1};
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>);
56 assert(ret == 1);
59 { // test that a two-element range works
60 int a[] = {1, 3};
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>);
63 assert(ret == 1);
66 { // test that a three-element range works
67 int a[] = {3, 1, 3};
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>);
70 assert(ret == 2);
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>);
77 assert(ret == 100);
82 int main(int, char**) {
83 types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{});
85 return 0;