xref: /llvm-project/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_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<InputIterator Iter1, ForwardIterator Iter2>
125a83710eSEric Fiselier //   requires HasEqualTo<Iter1::value_type, Iter2::value_type>
138694428eSMarshall Clow //   constexpr Iter1  // constexpr after C++17
145a83710eSEric Fiselier //   find_first_of(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
155a83710eSEric Fiselier 
165a83710eSEric Fiselier #include <algorithm>
175a83710eSEric Fiselier #include <cassert>
185a83710eSEric Fiselier 
198694428eSMarshall Clow #include "test_macros.h"
205a83710eSEric Fiselier #include "test_iterators.h"
215a83710eSEric Fiselier 
228694428eSMarshall Clow #if TEST_STD_VER > 17
test_constexpr()238694428eSMarshall Clow TEST_CONSTEXPR bool test_constexpr() {
248694428eSMarshall Clow     int ia[] = {1, 2, 3};
258694428eSMarshall Clow     int ib[] = {7, 8, 9};
268694428eSMarshall Clow     int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3};
278694428eSMarshall Clow     typedef forward_iterator<int*>       FI;
288694428eSMarshall Clow     typedef bidirectional_iterator<int*> BI;
298694428eSMarshall Clow     typedef random_access_iterator<int*> RI;
308694428eSMarshall Clow 
318694428eSMarshall Clow     return    (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ia)), FI(std::end(ia))) == FI(ic+1))
328694428eSMarshall Clow            && (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ib)), FI(std::end(ib))) == FI(std::end(ic)))
338694428eSMarshall Clow            && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ia)), BI(std::end(ia))) == BI(ic+1))
348694428eSMarshall Clow            && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ib)), BI(std::end(ib))) == BI(std::end(ic)))
358694428eSMarshall Clow            && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ia)), RI(std::end(ia))) == RI(ic+1))
368694428eSMarshall Clow            && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ib)), RI(std::end(ib))) == RI(std::end(ic)))
378694428eSMarshall Clow            ;
388694428eSMarshall Clow     }
398694428eSMarshall Clow #endif
408694428eSMarshall Clow 
main(int,char **)412df59c50SJF Bastien int main(int, char**)
425a83710eSEric Fiselier {
435a83710eSEric Fiselier     int ia[] = {0, 1, 2, 3, 0, 1, 2, 3};
445a83710eSEric Fiselier     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
455a83710eSEric Fiselier     int ib[] = {1, 3, 5, 7};
465a83710eSEric Fiselier     const unsigned sb = sizeof(ib)/sizeof(ib[0]);
47*773ae441SChristopher Di Bella     assert(std::find_first_of(cpp17_input_iterator<const int*>(ia),
48*773ae441SChristopher Di Bella                               cpp17_input_iterator<const int*>(ia + sa),
495a83710eSEric Fiselier                               forward_iterator<const int*>(ib),
505a83710eSEric Fiselier                               forward_iterator<const int*>(ib + sb)) ==
51*773ae441SChristopher Di Bella                               cpp17_input_iterator<const int*>(ia+1));
525a83710eSEric Fiselier     int ic[] = {7};
53*773ae441SChristopher Di Bella     assert(std::find_first_of(cpp17_input_iterator<const int*>(ia),
54*773ae441SChristopher Di Bella                               cpp17_input_iterator<const int*>(ia + sa),
555a83710eSEric Fiselier                               forward_iterator<const int*>(ic),
565a83710eSEric Fiselier                               forward_iterator<const int*>(ic + 1)) ==
57*773ae441SChristopher Di Bella                               cpp17_input_iterator<const int*>(ia+sa));
58*773ae441SChristopher Di Bella     assert(std::find_first_of(cpp17_input_iterator<const int*>(ia),
59*773ae441SChristopher Di Bella                               cpp17_input_iterator<const int*>(ia + sa),
605a83710eSEric Fiselier                               forward_iterator<const int*>(ic),
615a83710eSEric Fiselier                               forward_iterator<const int*>(ic)) ==
62*773ae441SChristopher Di Bella                               cpp17_input_iterator<const int*>(ia+sa));
63*773ae441SChristopher Di Bella     assert(std::find_first_of(cpp17_input_iterator<const int*>(ia),
64*773ae441SChristopher Di Bella                               cpp17_input_iterator<const int*>(ia),
655a83710eSEric Fiselier                               forward_iterator<const int*>(ic),
665a83710eSEric Fiselier                               forward_iterator<const int*>(ic+1)) ==
67*773ae441SChristopher Di Bella                               cpp17_input_iterator<const int*>(ia));
688694428eSMarshall Clow 
698694428eSMarshall Clow #if TEST_STD_VER > 17
708694428eSMarshall Clow     static_assert(test_constexpr());
718694428eSMarshall Clow #endif
722df59c50SJF Bastien 
732df59c50SJF Bastien   return 0;
745a83710eSEric Fiselier }
75