libcxx

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

max_size.pass.cpp (1280B)


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