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// const_reference at(size_type n) const;
13//       reference at(size_type n);
14
15#include <__config>
16
17#if _LIBCPP_STD_VER > 11
18
19#include <experimental/dynarray>
20#include <cassert>
21
22#include <algorithm>
23#include <complex>
24#include <string>
25
26using std::experimental::dynarray;
27
28template <class T>
29void dyn_test_const ( const dynarray<T> &dyn, const std::initializer_list<T> &vals ) {
30    const T *data = dyn.data ();
31    auto it = vals.begin ();
32    for ( size_t i = 0; i < dyn.size(); ++i, ++it ) {
33        assert ( data + i == &dyn[i]);
34        assert ( *it == dyn[i]);
35        }
36    }
37
38template <class T>
39void dyn_test ( dynarray<T> &dyn, const std::initializer_list<T> &vals ) {
40    T *data = dyn.data ();
41    auto it = vals.begin ();
42    for ( size_t i = 0; i < dyn.size(); ++i, ++it ) {
43        assert ( data + i == &dyn[i]);
44        assert ( *it == dyn[i]);
45        }
46    }
47
48
49template <class T>
50void test ( std::initializer_list<T> vals ) {
51    typedef dynarray<T> dynA;
52
53    dynA d1 ( vals );
54    dyn_test ( d1, vals );
55    dyn_test_const ( d1, vals );
56    }
57
58int main()
59{
60    test ( { 1, 1, 2, 3, 5, 8 } );
61    test ( { 1., 1., 2., 3., 5., 8. } );
62    test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"),
63                std::string("5"), std::string("8")} );
64
65    test<int> ( {} );
66    test<std::complex<double>> ( {} );
67    test<std::string> ( {} );
68}
69#else
70int main() {}
71#endif
72