libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

resize_size_value.pass.cpp (1449B)


      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 // void resize(size_type sz, const value_type& x);
     14 
     15 #include <vector>
     16 #include <cassert>
     17 
     18 #include "min_allocator.h"
     19 
     20 int main()
     21 {
     22     {
     23         std::vector<bool> v(100);
     24         v.resize(50, 1);
     25         assert(v.size() == 50);
     26         assert(v.capacity() >= 100);
     27         assert(v == std::vector<bool>(50));
     28         v.resize(200, 1);
     29         assert(v.size() == 200);
     30         assert(v.capacity() >= 200);
     31         for (unsigned i = 0; i < 50; ++i)
     32             assert(v[i] == 0);
     33         for (unsigned i = 50; i < 200; ++i)
     34             assert(v[i] == 1);
     35     }
     36 #if TEST_STD_VER >= 11
     37     {
     38         std::vector<bool, min_allocator<bool>> v(100);
     39         v.resize(50, 1);
     40         assert(v.size() == 50);
     41         assert(v.capacity() >= 100);
     42         assert((v == std::vector<bool, min_allocator<bool>>(50)));
     43         v.resize(200, 1);
     44         assert(v.size() == 200);
     45         assert(v.capacity() >= 200);
     46         for (unsigned i = 0; i < 50; ++i)
     47             assert(v[i] == 0);
     48         for (unsigned i = 50; i < 200; ++i)
     49             assert(v[i] == 1);
     50     }
     51 #endif
     52 }