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