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