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 
14 #include <vector>
15 #include <cassert>
16 
17 #include "test_iterators.h"
18 #include "../../../stack_allocator.h"
19 #include "../../../min_allocator.h"
20 
21 template <class C, class Iterator>
22 void
23 test(Iterator first, Iterator last)
24 {
25     C c(first, last);
26     assert(c.__invariants());
27     assert(c.size() == std::distance(first, last));
28     for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
29         assert(*i == *first);
30 }
31 
32 int main()
33 {
34     int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
35     int* an = a + sizeof(a)/sizeof(a[0]);
36     test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an));
37     test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
38     test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
39     test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
40     test<std::vector<int> >(a, an);
41 
42     test<std::vector<int, stack_allocator<int, 63> > >(input_iterator<const int*>(a), input_iterator<const int*>(an));
43     test<std::vector<int, stack_allocator<int, 18> > >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
44     test<std::vector<int, stack_allocator<int, 18> > >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
45     test<std::vector<int, stack_allocator<int, 18> > >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
46     test<std::vector<int, stack_allocator<int, 18> > >(a, an);
47 #if __cplusplus >= 201103L
48     test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an));
49     test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
50     test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
51     test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
52     test<std::vector<int> >(a, an);
53 #endif
54 }
55