blob: 128328c2a7d2673dbd282e2eea37a9f21cffd6e6 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <vector>
11
12// vector(const vector& v, const allocator_type& a);
13
14#include <vector>
15#include <cassert>
Marshall Clow1b921882013-12-03 00:18:10 +000016#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000017#include "min_allocator.h"
Marshall Clow1f50f2d2014-05-08 14:14:06 +000018#include "asan_testing.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019
20template <class C>
21void
22test(const C& x, const typename C::allocator_type& a)
23{
24 unsigned s = x.size();
25 C c(x, a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070026 assert(c.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000027 assert(c.size() == s);
28 assert(c == x);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070029 assert(is_contiguous_container_asan_correct(c));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000030}
31
32int main()
33{
34 {
35 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
36 int* an = a + sizeof(a)/sizeof(a[0]);
37 test(std::vector<int>(a, an), std::allocator<int>());
38 }
39 {
40 std::vector<int, test_allocator<int> > l(3, 2, test_allocator<int>(5));
41 std::vector<int, test_allocator<int> > l2(l, test_allocator<int>(3));
42 assert(l2 == l);
43 assert(l2.get_allocator() == test_allocator<int>(3));
44 }
45 {
46 std::vector<int, other_allocator<int> > l(3, 2, other_allocator<int>(5));
47 std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3));
48 assert(l2 == l);
49 assert(l2.get_allocator() == other_allocator<int>(3));
50 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070051#if __cplusplus >= 201103L
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000052 {
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), min_allocator<int>());
56 }
57 {
58 std::vector<int, min_allocator<int> > l(3, 2, min_allocator<int>());
59 std::vector<int, min_allocator<int> > l2(l, min_allocator<int>());
60 assert(l2 == l);
61 assert(l2.get_allocator() == min_allocator<int>());
62 }
63#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064}