• 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 
18 #include "test_macros.h"
19 
20 // std::array is explicitly allowed to be initialized with A a = { init-list };.
21 // Disable the missing braces warning for this reason.
22 #include "disable_missing_braces_warning.h"
23 
main()24 int main()
25 {
26     {
27     typedef std::array<int, 5> C;
28     C c;
29     C::iterator i;
30     i = c.begin();
31     C::const_iterator j;
32     j = c.cbegin();
33     assert(i == j);
34     }
35     {
36     typedef std::array<int, 0> C;
37     C c;
38     C::iterator i;
39     i = c.begin();
40     C::const_iterator j;
41     j = c.cbegin();
42     assert(i == j);
43     }
44 
45 #if TEST_STD_VER > 11
46     { // N3644 testing
47         {
48         typedef std::array<int, 5> C;
49         C::iterator ii1{}, ii2{};
50         C::iterator ii4 = ii1;
51         C::const_iterator cii{};
52         assert ( ii1 == ii2 );
53         assert ( ii1 == ii4 );
54         assert ( ii1 == cii );
55 
56         assert ( !(ii1 != ii2 ));
57         assert ( !(ii1 != cii ));
58 
59         C c;
60         assert ( c.begin()   == std::begin(c));
61         assert ( c.cbegin()  == std::cbegin(c));
62         assert ( c.rbegin()  == std::rbegin(c));
63         assert ( c.crbegin() == std::crbegin(c));
64         assert ( c.end()     == std::end(c));
65         assert ( c.cend()    == std::cend(c));
66         assert ( c.rend()    == std::rend(c));
67         assert ( c.crend()   == std::crend(c));
68 
69         assert ( std::begin(c)   != std::end(c));
70         assert ( std::rbegin(c)  != std::rend(c));
71         assert ( std::cbegin(c)  != std::cend(c));
72         assert ( std::crbegin(c) != std::crend(c));
73         }
74         {
75         typedef std::array<int, 0> C;
76         C::iterator ii1{}, ii2{};
77         C::iterator ii4 = ii1;
78         C::const_iterator cii{};
79         assert ( ii1 == ii2 );
80         assert ( ii1 == ii4 );
81 
82         assert (!(ii1 != ii2 ));
83 
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 ( (ii1 <= cii ));
91         assert ( (cii <= ii1 ));
92         assert (!(ii1 >  cii ));
93         assert (!(cii >  ii1 ));
94         assert ( (ii1 >= cii ));
95         assert ( (cii >= ii1 ));
96         assert (cii - ii1 == 0);
97         assert (ii1 - cii == 0);
98 
99         C c;
100         assert ( c.begin()   == std::begin(c));
101         assert ( c.cbegin()  == std::cbegin(c));
102         assert ( c.rbegin()  == std::rbegin(c));
103         assert ( c.crbegin() == std::crbegin(c));
104         assert ( c.end()     == std::end(c));
105         assert ( c.cend()    == std::cend(c));
106         assert ( c.rend()    == std::rend(c));
107         assert ( c.crend()   == std::crend(c));
108 
109         assert ( std::begin(c)   == std::end(c));
110         assert ( std::rbegin(c)  == std::rend(c));
111         assert ( std::cbegin(c)  == std::cend(c));
112         assert ( std::crbegin(c) == std::crend(c));
113         }
114     }
115 #endif
116 #if TEST_STD_VER > 14
117     {
118         typedef std::array<int, 5> C;
119         constexpr C c{0,1,2,3,4};
120 
121         static_assert ( c.begin()   == std::begin(c), "");
122         static_assert ( c.cbegin()  == std::cbegin(c), "");
123         static_assert ( c.end()     == std::end(c), "");
124         static_assert ( c.cend()    == std::cend(c), "");
125 
126         static_assert ( c.rbegin()  == std::rbegin(c), "");
127         static_assert ( c.crbegin() == std::crbegin(c), "");
128         static_assert ( c.rend()    == std::rend(c), "");
129         static_assert ( c.crend()   == std::crend(c), "");
130 
131         static_assert ( std::begin(c)   != std::end(c), "");
132         static_assert ( std::rbegin(c)  != std::rend(c), "");
133         static_assert ( std::cbegin(c)  != std::cend(c), "");
134         static_assert ( std::crbegin(c) != std::crend(c), "");
135 
136         static_assert ( *c.begin()  == 0, "");
137         static_assert ( *c.rbegin()  == 4, "");
138 
139         static_assert ( *std::begin(c)   == 0, "" );
140         static_assert ( *std::cbegin(c)  == 0, "" );
141         static_assert ( *std::rbegin(c)  == 4, "" );
142         static_assert ( *std::crbegin(c) == 4, "" );
143     }
144 #endif
145 }
146