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 // vector<bool>
     12 
     13 // explicit vector(size_type n);
     14 
     15 #include <vector>
     16 #include <cassert>
     17 
     18 #include "test_macros.h"
     19 #include "min_allocator.h"
     20 #include "test_allocator.h"
     21 
     22 template <class C>
     23 void
     24 test2(typename C::size_type n,
     25       typename C::allocator_type const& a = typename C::allocator_type ())
     26 {
     27 #if TEST_STD_VER >= 14
     28     C c(n, a);
     29     LIBCPP_ASSERT(c.__invariants());
     30     assert(c.size() == n);
     31     assert(c.get_allocator() == a);
     32     for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
     33         assert(*i == typename C::value_type());
     34 #endif
     35 }
     36 
     37 template <class C>
     38 void
     39 test1(typename C::size_type n)
     40 {
     41     C c(n);
     42     LIBCPP_ASSERT(c.__invariants());
     43     assert(c.size() == n);
     44     assert(c.get_allocator() == typename C::allocator_type());
     45     for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
     46         assert(*i == typename C::value_type());
     47 }
     48 
     49 template <class C>
     50 void
     51 test(typename C::size_type n)
     52 {
     53     test1<C> ( n );
     54     test2<C> ( n );
     55 }
     56 
     57 int main()
     58 {
     59     test<std::vector<bool> >(50);
     60 #if TEST_STD_VER >= 11
     61     test<std::vector<bool, min_allocator<bool>> >(50);
     62     test2<std::vector<bool, test_allocator<bool>> >( 100, test_allocator<bool>(23));
     63 #endif
     64 }
     65