]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/libcxx/experimental/containers/sequences/dynarray/dynarray.overview/front_back.pass.cpp
Vendor import of libc++ trunk r302418:
[FreeBSD/FreeBSD.git] / test / libcxx / experimental / containers / sequences / dynarray / dynarray.overview / front_back.pass.cpp
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.overview
14
15 // reference       front();
16 // const_reference front() const;
17 // reference       back();
18 // const_reference back()  const;
19
20
21 #include <experimental/dynarray>
22 #include <cassert>
23
24 #include <algorithm>
25 #include <complex>
26 #include <string>
27
28 using std::experimental::dynarray;
29
30 template <class T>
31 void dyn_test_const ( const dynarray<T> &dyn, bool CheckValues = true ) {
32     const T *data = dyn.data ();
33     assert(data == &dyn.front());
34     assert((data + dyn.size() - 1) == &dyn.back());
35     if (CheckValues) {
36         assert ( *data == dyn.front ());
37         assert ( *(data + dyn.size() - 1 ) == dyn.back ());
38     }
39 }
40
41 template <class T>
42 void dyn_test ( dynarray<T> &dyn, bool CheckValues = true ) {
43     T *data = dyn.data ();
44     assert(data == &dyn.front());
45     assert((data + dyn.size() - 1) == &dyn.back());
46     if (CheckValues) {
47         assert ( *data == dyn.front ());
48         assert ( *(data + dyn.size() - 1 ) == dyn.back ());
49     }
50 }
51
52
53 template <class T>
54 void test ( const T &val, bool DefaultValueIsIndeterminate = false) {
55     typedef dynarray<T> dynA;
56
57     const bool CheckDefaultValues = ! DefaultValueIsIndeterminate;
58
59     dynA d1 ( 4 );
60     dyn_test ( d1, CheckDefaultValues );
61     dyn_test_const ( d1, CheckDefaultValues );
62
63     dynA d2 ( 7, val );
64     dyn_test ( d2 );
65     dyn_test_const ( d2 );
66 }
67
68 int main()
69 {
70     test<int> ( 14, /* DefaultValueIsIndeterminate */ true);
71     test<double> ( 14.0, true );
72     test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
73     test<std::string> ( "fourteen" );
74 }