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 // <vector> 11 12 // template <class InputIter> vector(InputIter first, InputIter last, 13 // const allocator_type& a); 14 15 #include <vector> 16 #include <cassert> 17 #include <cstddef> 18 19 #include "test_macros.h" 20 #include "test_iterators.h" 21 #include "test_allocator.h" 22 #include "min_allocator.h" 23 #include "asan_testing.h" 24 25 template <class C, class Iterator, class A> 26 void 27 test(Iterator first, Iterator last, const A& a) 28 { 29 C c(first, last, a); 30 LIBCPP_ASSERT(c.__invariants()); 31 assert(c.size() == static_cast<std::size_t>(std::distance(first, last))); 32 LIBCPP_ASSERT(is_contiguous_container_asan_correct(c)); 33 for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) 34 assert(*i == *first); 35 } 36 37 #if TEST_STD_VER >= 11 38 39 template <class T> 40 struct implicit_conv_allocator : min_allocator<T> 41 { 42 implicit_conv_allocator(void*) {} 43 implicit_conv_allocator(const implicit_conv_allocator&) = default; 44 45 template <class U> 46 implicit_conv_allocator(implicit_conv_allocator<U>) {} 47 }; 48 49 #endif 50 51 int main() 52 { 53 { 54 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; 55 int* an = a + sizeof(a)/sizeof(a[0]); 56 std::allocator<int> alloc; 57 test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc); 58 test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc); 59 test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc); 60 test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc); 61 test<std::vector<int> >(a, an, alloc); 62 } 63 #if TEST_STD_VER >= 11 64 { 65 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; 66 int* an = a + sizeof(a)/sizeof(a[0]); 67 min_allocator<int> alloc; 68 test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc); 69 test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc); 70 test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc); 71 test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc); 72 test<std::vector<int, min_allocator<int>> >(a, an, alloc); 73 test<std::vector<int, implicit_conv_allocator<int>> >(a, an, nullptr); 74 } 75 #endif 76 } 77