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, class T>
12 //   requires HasEqualTo<Iter::value_type, T>
13 //   constexpr Iter::difference_type   // constexpr after C++17
14 //   count(Iter first, Iter last, const T& value);
15 
16 #include <algorithm>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "test_iterators.h"
21 
22 #if TEST_STD_VER > 17
test_constexpr()23 TEST_CONSTEXPR bool test_constexpr() {
24     int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
25     int ib[] = {1, 2, 3, 4, 5, 6};
26     return    (std::count(std::begin(ia), std::end(ia), 2) == 3)
27            && (std::count(std::begin(ib), std::end(ib), 9) == 0)
28            ;
29     }
30 #endif
31 
main(int,char **)32 int main(int, char**)
33 {
34     int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
35     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
36     assert(std::count(cpp17_input_iterator<const int*>(ia),
37                       cpp17_input_iterator<const int*>(ia + sa), 2) == 3);
38     assert(std::count(cpp17_input_iterator<const int*>(ia),
39                       cpp17_input_iterator<const int*>(ia + sa), 7) == 0);
40     assert(std::count(cpp17_input_iterator<const int*>(ia),
41                       cpp17_input_iterator<const int*>(ia), 2) == 0);
42 
43 #if TEST_STD_VER > 17
44     static_assert(test_constexpr());
45 #endif
46 
47   return 0;
48 }
49