libcxx

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

max_size.pass.cpp (1591B)


      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 // <unordered_map>
     11 
     12 // class unordered_multimap
     13 
     14 // size_type max_size() const;
     15 
     16 #include <cassert>
     17 #include <limits>
     18 #include <type_traits>
     19 #include <unordered_map>
     20 
     21 #include "test_allocator.h"
     22 #include "test_macros.h"
     23 
     24 int main()
     25 {
     26   typedef std::pair<const int, int> KV;
     27   {
     28     typedef limited_allocator<KV, 10> A;
     29     typedef std::unordered_multimap<int, int, std::hash<int>,
     30                                     std::equal_to<int>, A>
     31         C;
     32     C c;
     33     assert(c.max_size() <= 10);
     34     LIBCPP_ASSERT(c.max_size() == 10);
     35   }
     36   {
     37     typedef limited_allocator<KV, (size_t)-1> A;
     38     typedef std::unordered_multimap<int, int, std::hash<int>,
     39                                     std::equal_to<int>, A>
     40         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     LIBCPP_ASSERT(c.max_size() == max_dist);
     46     }
     47     {
     48       typedef std::unordered_multimap<char, int> C;
     49     const C::size_type max_dist =
     50         static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
     51       C c;
     52       assert(c.max_size() <= max_dist);
     53       assert(c.max_size() <= alloc_max_size(c.get_allocator()));
     54     }
     55 }