• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_macros.h"
20 #include "test_iterators.h"
21 
22 template <class Iter>
23 void
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 
main(int,char **)55 int main(int, char**)
56 {
57     test<bidirectional_iterator<int*> >();
58     test<random_access_iterator<int*> >();
59     test<int*>();
60 
61   return 0;
62 }
63