• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <array>
11 
12 // iterator, const_iterator
13 
14 #include <array>
15 #include <iterator>
16 #include <cassert>
17 
main()18 int main()
19 {
20     {
21     typedef std::array<int, 5> C;
22     C c;
23     C::iterator i;
24     i = c.begin();
25     C::const_iterator j;
26     j = c.cbegin();
27     assert(i == j);
28     }
29     {
30     typedef std::array<int, 0> C;
31     C c;
32     C::iterator i;
33     i = c.begin();
34     C::const_iterator j;
35     j = c.cbegin();
36     assert(i == j);
37     }
38 
39 #if _LIBCPP_STD_VER > 11
40     { // N3644 testing
41         {
42         typedef std::array<int, 5> C;
43         C::iterator ii1{}, ii2{};
44         C::iterator ii4 = ii1;
45         C::const_iterator cii{};
46         assert ( ii1 == ii2 );
47         assert ( ii1 == ii4 );
48         assert ( ii1 == cii );
49 
50         assert ( !(ii1 != ii2 ));
51         assert ( !(ii1 != cii ));
52 
53         C c;
54         assert ( c.begin()   == std::begin(c));
55         assert ( c.cbegin()  == std::cbegin(c));
56         assert ( c.rbegin()  == std::rbegin(c));
57         assert ( c.crbegin() == std::crbegin(c));
58         assert ( c.end()     == std::end(c));
59         assert ( c.cend()    == std::cend(c));
60         assert ( c.rend()    == std::rend(c));
61         assert ( c.crend()   == std::crend(c));
62 
63         assert ( std::begin(c)   != std::end(c));
64         assert ( std::rbegin(c)  != std::rend(c));
65         assert ( std::cbegin(c)  != std::cend(c));
66         assert ( std::crbegin(c) != std::crend(c));
67         }
68         {
69         typedef std::array<int, 0> C;
70         C::iterator ii1{}, ii2{};
71         C::iterator ii4 = ii1;
72         C::const_iterator cii{};
73         assert ( ii1 == ii2 );
74         assert ( ii1 == ii4 );
75 
76         assert (!(ii1 != ii2 ));
77 
78         assert ( (ii1 == cii ));
79         assert ( (cii == ii1 ));
80         assert (!(ii1 != cii ));
81         assert (!(cii != ii1 ));
82         assert (!(ii1 <  cii ));
83         assert (!(cii <  ii1 ));
84         assert ( (ii1 <= cii ));
85         assert ( (cii <= ii1 ));
86         assert (!(ii1 >  cii ));
87         assert (!(cii >  ii1 ));
88         assert ( (ii1 >= cii ));
89         assert ( (cii >= ii1 ));
90         assert (cii - ii1 == 0);
91         assert (ii1 - cii == 0);
92 
93         C c;
94         assert ( c.begin()   == std::begin(c));
95         assert ( c.cbegin()  == std::cbegin(c));
96         assert ( c.rbegin()  == std::rbegin(c));
97         assert ( c.crbegin() == std::crbegin(c));
98         assert ( c.end()     == std::end(c));
99         assert ( c.cend()    == std::cend(c));
100         assert ( c.rend()    == std::rend(c));
101         assert ( c.crend()   == std::crend(c));
102 
103         assert ( std::begin(c)   == std::end(c));
104         assert ( std::rbegin(c)  == std::rend(c));
105         assert ( std::cbegin(c)  == std::cend(c));
106         assert ( std::crbegin(c) == std::crend(c));
107         }
108     }
109 #endif
110 }
111