Home | History | Annotate | Download | only in dynarray.data
      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 // XFAIL: availability
     12 
     13 // dynarray.data
     14 
     15 // T* data() noexcept;
     16 // const T* data() const noexcept;
     17 
     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>
     29 void dyn_test_const(const dynarray<T> &dyn, bool CheckEquals = true) {
     30     const T *data = dyn.data ();
     31     assert ( data != NULL );
     32     if (CheckEquals) {
     33         assert ( std::equal ( dyn.begin(), dyn.end(), data ));
     34     }
     35 }
     36 
     37 template <class T>
     38 void dyn_test( dynarray<T> &dyn, bool CheckEquals = true) {
     39     T *data = dyn.data ();
     40     assert ( data != NULL );
     41     if (CheckEquals) {
     42         assert ( std::equal ( dyn.begin(), dyn.end(), data ));
     43     }
     44 }
     45 
     46 
     47 
     48 template <class T>
     49 void test(const T &val, bool DefaultValueIsIndeterminate = false) {
     50     typedef dynarray<T> dynA;
     51 
     52     const bool CheckDefaultValues = !DefaultValueIsIndeterminate;
     53 
     54     dynA d1(4);
     55     dyn_test(d1, CheckDefaultValues);
     56     dyn_test_const(d1, CheckDefaultValues);
     57 
     58     dynA d2 (7, val);
     59     dyn_test ( d2 );
     60     dyn_test_const ( d2 );
     61 }
     62 
     63 int main()
     64 {
     65     test<int>(14, /* DefaultValueIsIndeterminate */ true);
     66     test<double>(14.0, true);
     67     test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
     68     test<std::string> ( "fourteen" );
     69 }
     70