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 // UNSUPPORTED: c++98, c++03, c++11
11 
12 // dynarray.data
13 
14 // T* data() noexcept;
15 // const T* data() const noexcept;
16 
17 
18 #include <experimental/dynarray>
19 #include <cassert>
20 
21 #include <algorithm>
22 #include <complex>
23 #include <string>
24 
25 using std::experimental::dynarray;
26 
27 template <class T>
dyn_test_const(const dynarray<T> & dyn,bool CheckEquals=true)28 void dyn_test_const(const dynarray<T> &dyn, bool CheckEquals = true) {
29     const T *data = dyn.data ();
30     assert ( data != NULL );
31     if (CheckEquals) {
32         assert ( std::equal ( dyn.begin(), dyn.end(), data ));
33     }
34 }
35 
36 template <class T>
dyn_test(dynarray<T> & dyn,bool CheckEquals=true)37 void dyn_test( dynarray<T> &dyn, bool CheckEquals = true) {
38     T *data = dyn.data ();
39     assert ( data != NULL );
40     if (CheckEquals) {
41         assert ( std::equal ( dyn.begin(), dyn.end(), data ));
42     }
43 }
44 
45 
46 
47 template <class T>
test(const T & val,bool DefaultValueIsIndeterminate=false)48 void test(const T &val, bool DefaultValueIsIndeterminate = false) {
49     typedef dynarray<T> dynA;
50 
51     const bool CheckDefaultValues = !DefaultValueIsIndeterminate;
52 
53     dynA d1(4);
54     dyn_test(d1, CheckDefaultValues);
55     dyn_test_const(d1, CheckDefaultValues);
56 
57     dynA d2 (7, val);
58     dyn_test ( d2 );
59     dyn_test_const ( d2 );
60 }
61 
main()62 int main()
63 {
64     test<int>(14, /* DefaultValueIsIndeterminate */ true);
65     test<double>(14.0, true);
66     test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
67     test<std::string> ( "fourteen" );
68 }
69