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 // dynarray.overview
11
12
13 // iterator begin() noexcept;
14 // const_iterator begin() const noexcept;
15 // const_iterator cbegin() const noexcept;
16 // iterator end() noexcept;
17 // const_iterator end() const noexcept;
18 // const_iterator cend() const noexcept;
19 //
20 // reverse_iterator rbegin() noexcept;
21 // const_reverse_iterator rbegin() const noexcept;
22 // const_reverse_iterator crbegin() const noexcept;
23 // reverse_iterator rend() noexcept;
24 // const_reverse_iterator rend() const noexcept;
25 // const_reverse_iterator crend() const noexcept;
26
27
28 #include <__config>
29
30 #if _LIBCPP_STD_VER > 11
31
32 #include <experimental/dynarray>
33 #include <cassert>
34
35 #include <algorithm>
36 #include <complex>
37 #include <string>
38
39 using std::experimental::dynarray;
40
41 template <class T>
dyn_test_const(const dynarray<T> & dyn)42 void dyn_test_const ( const dynarray<T> &dyn ) {
43 const T *data = dyn.data ();
44 assert ( data == &*dyn.begin ());
45 assert ( data == &*dyn.cbegin ());
46
47 assert ( data + dyn.size() - 1 == &*dyn.rbegin ());
48 assert ( data + dyn.size() - 1 == &*dyn.crbegin ());
49
50 assert ( dyn.size () == std::distance ( dyn.begin(), dyn.end()));
51 assert ( dyn.size () == std::distance ( dyn.cbegin(), dyn.cend()));
52 assert ( dyn.size () == std::distance ( dyn.rbegin(), dyn.rend()));
53 assert ( dyn.size () == std::distance ( dyn.crbegin(), dyn.crend()));
54
55 assert ( dyn.begin () == dyn.cbegin ());
56 assert ( &*dyn.begin () == &*dyn.cbegin ());
57 assert ( dyn.rbegin () == dyn.crbegin ());
58 assert ( &*dyn.rbegin () == &*dyn.crbegin ());
59 assert ( dyn.end () == dyn.cend ());
60 assert ( dyn.rend () == dyn.crend ());
61 }
62
63 template <class T>
dyn_test(dynarray<T> & dyn)64 void dyn_test ( dynarray<T> &dyn ) {
65 T *data = dyn.data ();
66 assert ( data == &*dyn.begin ());
67 assert ( data == &*dyn.cbegin ());
68
69 assert ( data + dyn.size() - 1 == &*dyn.rbegin ());
70 assert ( data + dyn.size() - 1 == &*dyn.crbegin ());
71
72 assert ( dyn.size () == std::distance ( dyn.begin(), dyn.end()));
73 assert ( dyn.size () == std::distance ( dyn.cbegin(), dyn.cend()));
74 assert ( dyn.size () == std::distance ( dyn.rbegin(), dyn.rend()));
75 assert ( dyn.size () == std::distance ( dyn.crbegin(), dyn.crend()));
76
77 assert ( dyn.begin () == dyn.cbegin ());
78 assert ( &*dyn.begin () == &*dyn.cbegin ());
79 assert ( dyn.rbegin () == dyn.crbegin ());
80 assert ( &*dyn.rbegin () == &*dyn.crbegin ());
81 assert ( dyn.end () == dyn.cend ());
82 assert ( dyn.rend () == dyn.crend ());
83 }
84
85
86 template <class T>
test(const T & val)87 void test ( const T &val ) {
88 typedef dynarray<T> dynA;
89
90 dynA d1 ( 4 );
91 dyn_test ( d1 );
92 dyn_test_const ( d1 );
93
94 dynA d2 ( 7, val );
95 dyn_test ( d2 );
96 dyn_test_const ( d2 );
97 }
98
main()99 int main()
100 {
101 test<int> ( 14 );
102 test<double> ( 14.0 );
103 test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
104 test<std::string> ( "fourteen" );
105 }
106 #else
main()107 int main() {}
108 #endif
109