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 #include "../../../stack_allocator.h"
     17 #include "../../../MoveOnly.h"
     18 #include "min_allocator.h"
     19 #include "asan_testing.h"
     20 
     21 int main()
     22 {
     23 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     24     {
     25         std::vector<MoveOnly> v(100);
     26         v.resize(50);
     27         assert(v.size() == 50);
     28         assert(v.capacity() == 100);
     29         assert(is_contiguous_container_asan_correct(v));
     30         v.resize(200);
     31         assert(v.size() == 200);
     32         assert(v.capacity() >= 200);
     33         assert(is_contiguous_container_asan_correct(v));
     34     }
     35     {
     36         std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100);
     37         v.resize(50);
     38         assert(v.size() == 50);
     39         assert(v.capacity() == 100);
     40         assert(is_contiguous_container_asan_correct(v));
     41         v.resize(200);
     42         assert(v.size() == 200);
     43         assert(v.capacity() >= 200);
     44         assert(is_contiguous_container_asan_correct(v));
     45     }
     46 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     47     {
     48         std::vector<int> v(100);
     49         v.resize(50);
     50         assert(v.size() == 50);
     51         assert(v.capacity() == 100);
     52         assert(is_contiguous_container_asan_correct(v));
     53         v.resize(200);
     54         assert(v.size() == 200);
     55         assert(v.capacity() >= 200);
     56         assert(is_contiguous_container_asan_correct(v));
     57     }
     58     {
     59         std::vector<int, stack_allocator<int, 300> > v(100);
     60         v.resize(50);
     61         assert(v.size() == 50);
     62         assert(v.capacity() == 100);
     63         assert(is_contiguous_container_asan_correct(v));
     64         v.resize(200);
     65         assert(v.size() == 200);
     66         assert(v.capacity() >= 200);
     67         assert(is_contiguous_container_asan_correct(v));
     68     }
     69 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     70 #if __cplusplus >= 201103L
     71     {
     72         std::vector<MoveOnly, min_allocator<MoveOnly>> v(100);
     73         v.resize(50);
     74         assert(v.size() == 50);
     75         assert(v.capacity() == 100);
     76         assert(is_contiguous_container_asan_correct(v));
     77         v.resize(200);
     78         assert(v.size() == 200);
     79         assert(v.capacity() >= 200);
     80         assert(is_contiguous_container_asan_correct(v));
     81     }
     82 #endif
     83 }
     84