1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11
14 // explicit dynarray(size_type c);
15 // dynarray(size_type c, const T& v);
16 // dynarray(initializer_list<T>);
17 // dynarray(const dynarray& d);
22 #include <experimental/dynarray>
31 #include "test_macros.h"
34 using std::experimental::dynarray;
37 void testInitList( const std::initializer_list<T> &vals ) {
38 typedef dynarray<T> dynA;
41 assert ( d1.size () == vals.size() );
42 assert ( std::equal ( vals.begin (), vals.end (), d1.begin (), d1.end ()));
47 void test ( const T &val, bool DefaultValueIsIndeterminate = false) {
48 typedef dynarray<T> dynA;
51 assert ( d1.size () == 4 );
52 if (!DefaultValueIsIndeterminate) {
53 assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } ));
57 assert ( d2.size () == 7 );
58 assert ( std::all_of ( d2.begin (), d2.end (), [&val]( const T &item ){ return item == val; } ));
61 assert ( d3.size () == 7 );
62 assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ return item == val; } ));
65 #ifndef TEST_HAS_NO_EXCEPTIONS
66 void test_bad_length () {
67 try { dynarray<int> ( std::numeric_limits<size_t>::max() / sizeof ( int ) + 1 ); }
68 catch ( std::bad_array_length & ) { return ; }
69 catch (...) { assert(false); }
77 test<int> ( 14, /* DefaultValueIsIndeterminate */ true ); // ints don't get default initialized
78 test<long> ( 0, true);
79 test<double> ( 14.0, true );
80 test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
81 test<std::string> ( "fourteen" );
83 testInitList( { 1, 1, 2, 3, 5, 8 } );
84 testInitList( { 1., 1., 2., 3., 5., 8. } );
85 testInitList( { std::string("1"), std::string("1"), std::string("2"), std::string("3"),
86 std::string("5"), std::string("8")} );
88 // Make sure we don't pick up the Allocator version here
89 dynarray<long> d1 ( 20, 3 );
90 assert ( d1.size() == 20 );
91 assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return item == 3L; } ));
93 #ifndef TEST_HAS_NO_EXCEPTIONS