Home | History | Annotate | Download | only in vector.bool
      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 
     17 #include "test_macros.h"
     18 #include "test_allocator.h"
     19 #include "min_allocator.h"
     20 
     21 template <class C>
     22 void
     23 test(const C& x, const typename C::allocator_type& a)
     24 {
     25     unsigned s = x.size();
     26     C c(x, a);
     27     LIBCPP_ASSERT(c.__invariants());
     28     assert(c.size() == s);
     29     assert(c == x);
     30 }
     31 
     32 int 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<bool>(a, an), std::allocator<bool>());
     38     }
     39     {
     40         std::vector<bool, test_allocator<bool> > l(3, 2, test_allocator<bool>(5));
     41         std::vector<bool, test_allocator<bool> > l2(l, test_allocator<bool>(3));
     42         assert(l2 == l);
     43         assert(l2.get_allocator() == test_allocator<bool>(3));
     44     }
     45     {
     46         std::vector<bool, other_allocator<bool> > l(3, 2, other_allocator<bool>(5));
     47         std::vector<bool, other_allocator<bool> > l2(l, other_allocator<bool>(3));
     48         assert(l2 == l);
     49         assert(l2.get_allocator() == other_allocator<bool>(3));
     50     }
     51 #if TEST_STD_VER >= 11
     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<bool, min_allocator<bool>>(a, an), min_allocator<bool>());
     56     }
     57     {
     58         std::vector<bool, min_allocator<bool> > l(3, 2, min_allocator<bool>());
     59         std::vector<bool, min_allocator<bool> > l2(l, min_allocator<bool>());
     60         assert(l2 == l);
     61         assert(l2.get_allocator() == min_allocator<bool>());
     62     }
     63 #endif
     64 }
     65