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 // vector(const vector& v, const allocator_type& a);
13 
14 #include <vector>
15 #include <cassert>
16 #include "../../../test_allocator.h"
17 #include "../../../min_allocator.h"
18 
19 template <class C>
20 void
21 test(const C& x, const typename C::allocator_type& a)
22 {
23     unsigned s = x.size();
24     C c(x, a);
25     assert(c.__invariants());
26     assert(c.size() == s);
27     assert(c == x);
28 }
29 
30 int main()
31 {
32     {
33         int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
34         int* an = a + sizeof(a)/sizeof(a[0]);
35         test(std::vector<int>(a, an), std::allocator<int>());
36     }
37     {
38         std::vector<int, test_allocator<int> > l(3, 2, test_allocator<int>(5));
39         std::vector<int, test_allocator<int> > l2(l, test_allocator<int>(3));
40         assert(l2 == l);
41         assert(l2.get_allocator() == test_allocator<int>(3));
42     }
43     {
44         std::vector<int, other_allocator<int> > l(3, 2, other_allocator<int>(5));
45         std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3));
46         assert(l2 == l);
47         assert(l2.get_allocator() == other_allocator<int>(3));
48     }
49 #if __cplusplus >= 201103L
50     {
51         int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
52         int* an = a + sizeof(a)/sizeof(a[0]);
53         test(std::vector<int, min_allocator<int>>(a, an), min_allocator<int>());
54     }
55     {
56         std::vector<int, min_allocator<int> > l(3, 2, min_allocator<int>());
57         std::vector<int, min_allocator<int> > l2(l, min_allocator<int>());
58         assert(l2 == l);
59         assert(l2.get_allocator() == min_allocator<int>());
60     }
61 #endif
62 }
63