Home | History | Annotate | Download | only in alg.count
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <algorithm>
     11 
     12 // template<InputIterator Iter, class T>
     13 //   requires HasEqualTo<Iter::value_type, T>
     14 //   constexpr Iter::difference_type   // constexpr after C++17
     15 //   count(Iter first, Iter last, const T& value);
     16 
     17 #include <algorithm>
     18 #include <cassert>
     19 
     20 #include "test_macros.h"
     21 #include "test_iterators.h"
     22 
     23 #if TEST_STD_VER > 17
     24 TEST_CONSTEXPR bool test_constexpr() {
     25     int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
     26     int ib[] = {1, 2, 3, 4, 5, 6};
     27     return    (std::count(std::begin(ia), std::end(ia), 2) == 3)
     28            && (std::count(std::begin(ib), std::end(ib), 9) == 0)
     29            ;
     30     }
     31 #endif
     32 
     33 int main()
     34 {
     35     int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
     36     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     37     assert(std::count(input_iterator<const int*>(ia),
     38                       input_iterator<const int*>(ia + sa), 2) == 3);
     39     assert(std::count(input_iterator<const int*>(ia),
     40                       input_iterator<const int*>(ia + sa), 7) == 0);
     41     assert(std::count(input_iterator<const int*>(ia),
     42                       input_iterator<const int*>(ia), 2) == 0);
     43 
     44 #if TEST_STD_VER > 17
     45     static_assert(test_constexpr());
     46 #endif
     47 }
     48