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