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.cons
11 
12 // template <class Alloc>
13 //   dynarray(size_type c, const Alloc& alloc);
14 // template <class Alloc>
15 //   dynarray(size_type c, const T& v, const Alloc& alloc);
16 // template <class Alloc>
17 //   dynarray(const dynarray& d, const Alloc& alloc);
18 // template <class Alloc>
19 //   dynarray(initializer_list<T>, const Alloc& alloc);
20 
21 // ~dynarray();
22 
23 
24 #include <__config>
25 
26 #if _LIBCPP_STD_VER > 11
27 
28 #include <experimental/dynarray>
29 #include <cassert>
30 
31 #include <algorithm>
32 #include <complex>
33 #include <string>
34 #include "test_allocator.h"
35 
36 using std::experimental::dynarray;
37 
38 template <class T, class Allocator>
check_allocator(const dynarray<T> & dyn,const Allocator & alloc)39 void check_allocator ( const dynarray<T> &dyn, const Allocator &alloc ) {
40     for ( int i = 0; i < dyn.size (); ++i )
41         assert ( dyn[i].get_allocator() == alloc );
42 }
43 
44 template <class T, class Allocator>
test(const std::initializer_list<T> & vals,const Allocator & alloc)45 void test ( const std::initializer_list<T> &vals, const Allocator &alloc ) {
46     typedef dynarray<T> dynA;
47 
48     dynA d1 ( vals, alloc );
49     assert ( d1.size () == vals.size() );
50     assert ( std::equal ( vals.begin (), vals.end (), d1.begin (), d1.end ()));
51     check_allocator ( d1, alloc );
52     }
53 
54 
55 template <class T, class Allocator>
test(const T & val,const Allocator & alloc1,const Allocator & alloc2)56 void test ( const T &val, const Allocator &alloc1, const Allocator &alloc2 ) {
57     typedef dynarray<T> dynA;
58 
59     dynA d1 ( 4, alloc1 );
60     assert ( d1.size () == 4 );
61     assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } ));
62     check_allocator ( d1, alloc1 );
63 
64     dynA d2 ( 7, val, alloc1 );
65     assert ( d2.size () == 7 );
66     assert ( std::all_of ( d2.begin (), d2.end (), [&val]( const T &item ){ return item == val; } ));
67     check_allocator ( d2, alloc1 );
68 
69     dynA d3 ( d2, alloc2 );
70     assert ( d3.size () == 7 );
71     assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ return item == val; } ));
72     check_allocator ( d3, alloc2 );
73     }
74 
main()75 int main()
76 {
77 //  This test is waiting on the resolution of LWG issue #2235
78 //     typedef test_allocator<char> Alloc;
79 //     typedef std::basic_string<char, std::char_traits<char>, Alloc> nstr;
80 //
81 //     test ( nstr("fourteen"), Alloc(3), Alloc(4) );
82 //     test ( { nstr("1"), nstr("1"), nstr("2"), nstr("3"), nstr("5"), nstr("8")}, Alloc(6));
83 }
84 #else
main()85 int main() {}
86 #endif
87