xref: /llvm-project/libcxx/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp (revision 773ae4412468433c134e668b4047c94f4599e0fd)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // <algorithm>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // template <class InputIterator, class Predicate>
12530c69e9SArthur O'Dwyer //     constexpr bool       // constexpr after C++17
135a83710eSEric Fiselier //   all_of(InputIterator first, InputIterator last, Predicate pred);
145a83710eSEric Fiselier 
155a83710eSEric Fiselier #include <algorithm>
165a83710eSEric Fiselier #include <cassert>
175a83710eSEric Fiselier 
18706ffef7SMarshall Clow #include "test_macros.h"
195a83710eSEric Fiselier #include "test_iterators.h"
205a83710eSEric Fiselier 
215a83710eSEric Fiselier struct test1
225a83710eSEric Fiselier {
operator ()test123706ffef7SMarshall Clow     TEST_CONSTEXPR bool operator()(const int& i) const
245a83710eSEric Fiselier     {
255a83710eSEric Fiselier         return i % 2 == 0;
265a83710eSEric Fiselier     }
275a83710eSEric Fiselier };
285a83710eSEric Fiselier 
29706ffef7SMarshall Clow #if TEST_STD_VER > 17
test_constexpr()30404ee020SMarshall Clow TEST_CONSTEXPR bool test_constexpr() {
31706ffef7SMarshall Clow     int ia[] = {2, 4, 6, 8};
32706ffef7SMarshall Clow     int ib[] = {2, 4, 5, 8};
33706ffef7SMarshall Clow     return  std::all_of(std::begin(ia), std::end(ia), test1())
34706ffef7SMarshall Clow         && !std::all_of(std::begin(ib), std::end(ib), test1())
35706ffef7SMarshall Clow         ;
36706ffef7SMarshall Clow     }
37706ffef7SMarshall Clow #endif
38706ffef7SMarshall Clow 
main(int,char **)392df59c50SJF Bastien int main(int, char**)
405a83710eSEric Fiselier {
415a83710eSEric Fiselier     {
425a83710eSEric Fiselier         int ia[] = {2, 4, 6, 8};
435a83710eSEric Fiselier         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
44*773ae441SChristopher Di Bella         assert(std::all_of(cpp17_input_iterator<const int*>(ia),
45*773ae441SChristopher Di Bella                            cpp17_input_iterator<const int*>(ia + sa), test1()) == true);
46*773ae441SChristopher Di Bella         assert(std::all_of(cpp17_input_iterator<const int*>(ia),
47*773ae441SChristopher Di Bella                            cpp17_input_iterator<const int*>(ia), test1()) == true);
485a83710eSEric Fiselier     }
495a83710eSEric Fiselier     {
505a83710eSEric Fiselier         const int ia[] = {2, 4, 5, 8};
515a83710eSEric Fiselier         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
52*773ae441SChristopher Di Bella         assert(std::all_of(cpp17_input_iterator<const int*>(ia),
53*773ae441SChristopher Di Bella                            cpp17_input_iterator<const int*>(ia + sa), test1()) == false);
54*773ae441SChristopher Di Bella         assert(std::all_of(cpp17_input_iterator<const int*>(ia),
55*773ae441SChristopher Di Bella                            cpp17_input_iterator<const int*>(ia), test1()) == true);
565a83710eSEric Fiselier     }
57706ffef7SMarshall Clow 
58706ffef7SMarshall Clow #if TEST_STD_VER > 17
59706ffef7SMarshall Clow     static_assert(test_constexpr());
60706ffef7SMarshall Clow #endif
612df59c50SJF Bastien 
622df59c50SJF Bastien   return 0;
635a83710eSEric Fiselier }
64