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