Home | History | Annotate | Download | only in vector.capacity
      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 // void resize(size_type sz);
     13 
     14 #include <vector>
     15 #include <cassert>
     16 
     17 #include "test_macros.h"
     18 #include "test_allocator.h"
     19 #include "MoveOnly.h"
     20 #include "min_allocator.h"
     21 #include "asan_testing.h"
     22 
     23 int main()
     24 {
     25     {
     26         std::vector<int> v(100);
     27         v.resize(50);
     28         assert(v.size() == 50);
     29         assert(v.capacity() == 100);
     30         assert(is_contiguous_container_asan_correct(v));
     31         v.resize(200);
     32         assert(v.size() == 200);
     33         assert(v.capacity() >= 200);
     34         assert(is_contiguous_container_asan_correct(v));
     35     }
     36     {
     37         // Add 1 for implementations that dynamically allocate a container proxy.
     38         std::vector<int, limited_allocator<int, 300 + 1> > v(100);
     39         v.resize(50);
     40         assert(v.size() == 50);
     41         assert(v.capacity() == 100);
     42         assert(is_contiguous_container_asan_correct(v));
     43         v.resize(200);
     44         assert(v.size() == 200);
     45         assert(v.capacity() >= 200);
     46         assert(is_contiguous_container_asan_correct(v));
     47     }
     48 #if TEST_STD_VER >= 11
     49     {
     50         std::vector<MoveOnly> v(100);
     51         v.resize(50);
     52         assert(v.size() == 50);
     53         assert(v.capacity() == 100);
     54         assert(is_contiguous_container_asan_correct(v));
     55         v.resize(200);
     56         assert(v.size() == 200);
     57         assert(v.capacity() >= 200);
     58         assert(is_contiguous_container_asan_correct(v));
     59     }
     60     {
     61         // Add 1 for implementations that dynamically allocate a container proxy.
     62         std::vector<MoveOnly, limited_allocator<MoveOnly, 300 + 1> > v(100);
     63         v.resize(50);
     64         assert(v.size() == 50);
     65         assert(v.capacity() == 100);
     66         assert(is_contiguous_container_asan_correct(v));
     67         v.resize(200);
     68         assert(v.size() == 200);
     69         assert(v.capacity() >= 200);
     70         assert(is_contiguous_container_asan_correct(v));
     71     }
     72     {
     73         std::vector<MoveOnly, min_allocator<MoveOnly>> v(100);
     74         v.resize(50);
     75         assert(v.size() == 50);
     76         assert(v.capacity() == 100);
     77         assert(is_contiguous_container_asan_correct(v));
     78         v.resize(200);
     79         assert(v.size() == 200);
     80         assert(v.capacity() >= 200);
     81         assert(is_contiguous_container_asan_correct(v));
     82     }
     83 #endif
     84 }
     85