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 // size_type max_size() const;
     13 
     14 #include <cassert>
     15 #include <limits>
     16 #include <type_traits>
     17 #include <vector>
     18 
     19 #include "test_allocator.h"
     20 #include "test_macros.h"
     21 
     22 
     23 int main() {
     24   {
     25     typedef limited_allocator<int, 10> A;
     26     typedef std::vector<int, A> C;
     27     C c;
     28     assert(c.max_size() <= 10);
     29     LIBCPP_ASSERT(c.max_size() == 10);
     30   }
     31   {
     32     typedef limited_allocator<int, (size_t)-1> A;
     33     typedef std::vector<int, A> C;
     34     const C::difference_type max_dist =
     35         std::numeric_limits<C::difference_type>::max();
     36     C c;
     37     assert(c.max_size() <= max_dist);
     38     LIBCPP_ASSERT(c.max_size() == max_dist);
     39   }
     40   {
     41     typedef std::vector<char> C;
     42     const C::difference_type max_dist =
     43         std::numeric_limits<C::difference_type>::max();
     44     C c;
     45     assert(c.max_size() <= max_dist);
     46     assert(c.max_size() <= alloc_max_size(c.get_allocator()));
     47   }
     48 }
     49