• 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 // 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 
26 using std::experimental::dynarray;
27 
28 template <class T>
dyn_test_const(const dynarray<T> & dyn,const std::initializer_list<T> & vals)29 void 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 
38 template <class T>
dyn_test(dynarray<T> & dyn,const std::initializer_list<T> & vals)39 void 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 
49 template <class T>
test(std::initializer_list<T> vals)50 void 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 
main()58 int 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
main()70 int main() {}
71 #endif
72