blob: 58822782ff8b9a09592e895bd79a0e3912839f77 [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// vector<bool>
12
13// vector(const vector& v);
14
15#include <vector>
16#include <cassert>
Marshall Clow1b921882013-12-03 00:18:10 +000017#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000018#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019
20template <class C>
21void
22test(const C& x)
23{
24 unsigned s = x.size();
25 C c(x);
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);
29}
30
31int main()
32{
33 {
34 bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
35 bool* an = a + sizeof(a)/sizeof(a[0]);
36 test(std::vector<bool>(a, an));
37 }
38 {
39 std::vector<bool, test_allocator<bool> > v(3, 2, test_allocator<bool>(5));
40 std::vector<bool, test_allocator<bool> > v2 = v;
41 assert(v2 == v);
42 assert(v2.get_allocator() == v.get_allocator());
43 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070044#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045 {
46 std::vector<bool, other_allocator<bool> > v(3, 2, other_allocator<bool>(5));
47 std::vector<bool, other_allocator<bool> > v2 = v;
48 assert(v2 == v);
49 assert(v2.get_allocator() == other_allocator<bool>(-2));
50 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070051#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
52#if __cplusplus >= 201103L
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000053 {
54 bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
55 bool* an = a + sizeof(a)/sizeof(a[0]);
56 test(std::vector<bool, min_allocator<bool>>(a, an));
57 }
58 {
59 std::vector<bool, min_allocator<bool> > v(3, 2, min_allocator<bool>());
60 std::vector<bool, min_allocator<bool> > v2 = v;
61 assert(v2 == v);
62 assert(v2.get_allocator() == v.get_allocator());
63 }
64#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000065}