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 reserve(size_type n);
     13 
     14 #include <vector>
     15 #include <cassert>
     16 #include "../../../stack_allocator.h"
     17 #include "min_allocator.h"
     18 #include "asan_testing.h"
     19 
     20 int main()
     21 {
     22     {
     23         std::vector<int> v;
     24         v.reserve(10);
     25         assert(v.capacity() >= 10);
     26         assert(is_contiguous_container_asan_correct(v));
     27     }
     28     {
     29         std::vector<int> v(100);
     30         assert(v.capacity() == 100);
     31         v.reserve(50);
     32         assert(v.size() == 100);
     33         assert(v.capacity() == 100);
     34         v.reserve(150);
     35         assert(v.size() == 100);
     36         assert(v.capacity() == 150);
     37         assert(is_contiguous_container_asan_correct(v));
     38     }
     39     {
     40         std::vector<int, stack_allocator<int, 250> > v(100);
     41         assert(v.capacity() == 100);
     42         v.reserve(50);
     43         assert(v.size() == 100);
     44         assert(v.capacity() == 100);
     45         v.reserve(150);
     46         assert(v.size() == 100);
     47         assert(v.capacity() == 150);
     48         assert(is_contiguous_container_asan_correct(v));
     49     }
     50 #if __cplusplus >= 201103L
     51     {
     52         std::vector<int, min_allocator<int>> v;
     53         v.reserve(10);
     54         assert(v.capacity() >= 10);
     55         assert(is_contiguous_container_asan_correct(v));
     56     }
     57     {
     58         std::vector<int, min_allocator<int>> v(100);
     59         assert(v.capacity() == 100);
     60         v.reserve(50);
     61         assert(v.size() == 100);
     62         assert(v.capacity() == 100);
     63         v.reserve(150);
     64         assert(v.size() == 100);
     65         assert(v.capacity() == 150);
     66         assert(is_contiguous_container_asan_correct(v));
     67     }
     68 #endif
     69 }
     70