• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <class InputIterator, class Predicate>
13 //     constpexr bool       // constexpr after C++17
14 //   all_of(InputIterator first, InputIterator last, Predicate pred);
15 
16 #include <algorithm>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "test_iterators.h"
21 
22 struct test1
23 {
operator ()test124     TEST_CONSTEXPR bool operator()(const int& i) const
25     {
26         return i % 2 == 0;
27     }
28 };
29 
30 #if TEST_STD_VER > 17
test_constexpr()31 TEST_CONSTEXPR bool test_constexpr() {
32     int ia[] = {2, 4, 6, 8};
33     int ib[] = {2, 4, 5, 8};
34     return  std::all_of(std::begin(ia), std::end(ia), test1())
35         && !std::all_of(std::begin(ib), std::end(ib), test1())
36         ;
37     }
38 #endif
39 
main()40 int main()
41 {
42     {
43         int ia[] = {2, 4, 6, 8};
44         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
45         assert(std::all_of(input_iterator<const int*>(ia),
46                            input_iterator<const int*>(ia + sa), test1()) == true);
47         assert(std::all_of(input_iterator<const int*>(ia),
48                            input_iterator<const int*>(ia), test1()) == true);
49     }
50     {
51         const int ia[] = {2, 4, 5, 8};
52         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
53         assert(std::all_of(input_iterator<const int*>(ia),
54                            input_iterator<const int*>(ia + sa), test1()) == false);
55         assert(std::all_of(input_iterator<const int*>(ia),
56                            input_iterator<const int*>(ia), test1()) == true);
57     }
58 
59 #if TEST_STD_VER > 17
60     static_assert(test_constexpr());
61 #endif
62 }
63