1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <algorithm>
10 
11 // template<BidirectionalIterator Iter>
12 //   requires HasSwap<Iter::reference, Iter::reference>
13 //   constexpr void  // constexpr in C++20
14 //   reverse(Iter first, Iter last);
15 
16 #include <algorithm>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "test_iterators.h"
21 
22 template <class Iter>
23 TEST_CONSTEXPR_CXX20 bool
test()24 test()
25 {
26     int ia[] = {0};
27     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
28     std::reverse(Iter(ia), Iter(ia));
29     assert(ia[0] == 0);
30     std::reverse(Iter(ia), Iter(ia+sa));
31     assert(ia[0] == 0);
32 
33     int ib[] = {0, 1};
34     const unsigned sb = sizeof(ib)/sizeof(ib[0]);
35     std::reverse(Iter(ib), Iter(ib+sb));
36     assert(ib[0] == 1);
37     assert(ib[1] == 0);
38 
39     int ic[] = {0, 1, 2};
40     const unsigned sc = sizeof(ic)/sizeof(ic[0]);
41     std::reverse(Iter(ic), Iter(ic+sc));
42     assert(ic[0] == 2);
43     assert(ic[1] == 1);
44     assert(ic[2] == 0);
45 
46     int id[] = {0, 1, 2, 3};
47     const unsigned sd = sizeof(id)/sizeof(id[0]);
48     std::reverse(Iter(id), Iter(id+sd));
49     assert(id[0] == 3);
50     assert(id[1] == 2);
51     assert(id[2] == 1);
52     assert(id[3] == 0);
53 
54     return true;
55 }
56 
main(int,char **)57 int main(int, char**)
58 {
59     test<bidirectional_iterator<int*> >();
60     test<random_access_iterator<int*> >();
61     test<int*>();
62 
63 #if TEST_STD_VER >= 20
64     static_assert(test<bidirectional_iterator<int*>>());
65     static_assert(test<random_access_iterator<int*>>());
66     static_assert(test<int*>());
67 #endif
68 
69     return 0;
70 }
71