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 //   void
14 //   reverse(Iter first, Iter last);
15 
16 #include <algorithm>
17 #include <cassert>
18 
19 #include "test_iterators.h"
20 
21 template <class Iter>
22 void
23 test()
24 {
25     int ia[] = {0};
26     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
27     std::reverse(Iter(ia), Iter(ia));
28     assert(ia[0] == 0);
29     std::reverse(Iter(ia), Iter(ia+sa));
30     assert(ia[0] == 0);
31 
32     int ib[] = {0, 1};
33     const unsigned sb = sizeof(ib)/sizeof(ib[0]);
34     std::reverse(Iter(ib), Iter(ib+sb));
35     assert(ib[0] == 1);
36     assert(ib[1] == 0);
37 
38     int ic[] = {0, 1, 2};
39     const unsigned sc = sizeof(ic)/sizeof(ic[0]);
40     std::reverse(Iter(ic), Iter(ic+sc));
41     assert(ic[0] == 2);
42     assert(ic[1] == 1);
43     assert(ic[2] == 0);
44 
45     int id[] = {0, 1, 2, 3};
46     const unsigned sd = sizeof(id)/sizeof(id[0]);
47     std::reverse(Iter(id), Iter(id+sd));
48     assert(id[0] == 3);
49     assert(id[1] == 2);
50     assert(id[2] == 1);
51     assert(id[3] == 0);
52 }
53 
54 int main(int, char**)
55 {
56     test<bidirectional_iterator<int*> >();
57     test<random_access_iterator<int*> >();
58     test<int*>();
59 
60   return 0;
61 }
62