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, InputIterator Iter2>
125a83710eSEric Fiselier // requires HasEqualTo<Iter1::value_type, Iter2::value_type>
136538e28dSMarshall Clow // constexpr bool // constexpr after c++17
145a83710eSEric Fiselier // equal(Iter1 first1, Iter1 last1, Iter2 first2);
156538e28dSMarshall Clow //
166538e28dSMarshall Clow // Introduced in C++14:
176538e28dSMarshall Clow // template<InputIterator Iter1, InputIterator Iter2>
186538e28dSMarshall Clow // constexpr bool // constexpr after c++17
196538e28dSMarshall Clow // equal(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
205a83710eSEric Fiselier
215a83710eSEric Fiselier #include <algorithm>
225a83710eSEric Fiselier #include <cassert>
235a83710eSEric Fiselier
24e58baed3SEric Fiselier #include "test_macros.h"
255a83710eSEric Fiselier #include "test_iterators.h"
265a83710eSEric Fiselier
276538e28dSMarshall Clow #if TEST_STD_VER > 17
test_constexpr()286538e28dSMarshall Clow TEST_CONSTEXPR bool test_constexpr() {
296538e28dSMarshall Clow int ia[] = {1, 3, 6, 7};
306538e28dSMarshall Clow int ib[] = {1, 3};
316538e28dSMarshall Clow int ic[] = {1, 3, 5, 7};
32*773ae441SChristopher Di Bella typedef cpp17_input_iterator<int*> II;
336538e28dSMarshall Clow typedef bidirectional_iterator<int*> BI;
346538e28dSMarshall Clow
356538e28dSMarshall Clow return !std::equal(std::begin(ia), std::end(ia), std::begin(ic))
366538e28dSMarshall Clow && !std::equal(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic))
376538e28dSMarshall Clow && std::equal(std::begin(ib), std::end(ib), std::begin(ic))
386538e28dSMarshall Clow && !std::equal(std::begin(ib), std::end(ib), std::begin(ic), std::end(ic))
396538e28dSMarshall Clow
406538e28dSMarshall Clow && std::equal(II(std::begin(ib)), II(std::end(ib)), II(std::begin(ic)))
416538e28dSMarshall Clow && !std::equal(BI(std::begin(ib)), BI(std::end(ib)), BI(std::begin(ic)), BI(std::end(ic)))
426538e28dSMarshall Clow ;
436538e28dSMarshall Clow }
446538e28dSMarshall Clow #endif
456538e28dSMarshall Clow
465a83710eSEric Fiselier
main(int,char **)472df59c50SJF Bastien int main(int, char**)
485a83710eSEric Fiselier {
495a83710eSEric Fiselier int ia[] = {0, 1, 2, 3, 4, 5};
505a83710eSEric Fiselier const unsigned s = sizeof(ia)/sizeof(ia[0]);
515a83710eSEric Fiselier int ib[s] = {0, 1, 2, 5, 4, 5};
52*773ae441SChristopher Di Bella assert(std::equal(cpp17_input_iterator<const int*>(ia),
53*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia+s),
54*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia)));
55e58baed3SEric Fiselier #if TEST_STD_VER >= 14
56*773ae441SChristopher Di Bella assert(std::equal(cpp17_input_iterator<const int*>(ia),
57*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia+s),
58*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia),
59*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia+s)));
605a83710eSEric Fiselier assert(std::equal(random_access_iterator<const int*>(ia),
615a83710eSEric Fiselier random_access_iterator<const int*>(ia+s),
625a83710eSEric Fiselier random_access_iterator<const int*>(ia),
635a83710eSEric Fiselier random_access_iterator<const int*>(ia+s)));
645a83710eSEric Fiselier #endif
65*773ae441SChristopher Di Bella assert(!std::equal(cpp17_input_iterator<const int*>(ia),
66*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia+s),
67*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ib)));
68e58baed3SEric Fiselier #if TEST_STD_VER >= 14
69*773ae441SChristopher Di Bella assert(!std::equal(cpp17_input_iterator<const int*>(ia),
70*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia+s),
71*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ib),
72*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ib+s)));
735a83710eSEric Fiselier assert(!std::equal(random_access_iterator<const int*>(ia),
745a83710eSEric Fiselier random_access_iterator<const int*>(ia+s),
755a83710eSEric Fiselier random_access_iterator<const int*>(ib),
765a83710eSEric Fiselier random_access_iterator<const int*>(ib+s)));
77*773ae441SChristopher Di Bella assert(!std::equal(cpp17_input_iterator<const int*>(ia),
78*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia+s),
79*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia),
80*773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(ia+s-1)));
815a83710eSEric Fiselier assert(!std::equal(random_access_iterator<const int*>(ia),
825a83710eSEric Fiselier random_access_iterator<const int*>(ia+s),
835a83710eSEric Fiselier random_access_iterator<const int*>(ia),
845a83710eSEric Fiselier random_access_iterator<const int*>(ia+s-1)));
855a83710eSEric Fiselier
865a83710eSEric Fiselier #endif
876538e28dSMarshall Clow
886538e28dSMarshall Clow #if TEST_STD_VER > 17
896538e28dSMarshall Clow static_assert(test_constexpr());
906538e28dSMarshall Clow #endif
912df59c50SJF Bastien
922df59c50SJF Bastien return 0;
935a83710eSEric Fiselier }
94