Home | History | Annotate | Download | only in unord.multimap.modifiers
      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 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
     13 //           class Alloc = allocator<pair<const Key, T>>>
     14 // class unordered_multimap
     15 
     16 // void insert(initializer_list<value_type> il);
     17 
     18 #include <unordered_map>
     19 #include <string>
     20 #include <cassert>
     21 #include <cstddef>
     22 
     23 #include "test_iterators.h"
     24 #include "min_allocator.h"
     25 
     26 int main()
     27 {
     28 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     29     {
     30         typedef std::unordered_multimap<int, std::string> C;
     31         typedef std::pair<int, std::string> P;
     32         C c;
     33         c.insert(
     34                     {
     35                         P(1, "one"),
     36                         P(2, "two"),
     37                         P(3, "three"),
     38                         P(4, "four"),
     39                         P(1, "four"),
     40                         P(2, "four"),
     41                     }
     42                 );
     43         assert(c.size() == 6);
     44         typedef std::pair<C::iterator, C::iterator> Eq;
     45         Eq eq = c.equal_range(1);
     46         assert(std::distance(eq.first, eq.second) == 2);
     47         C::iterator k = eq.first;
     48         assert(k->first == 1);
     49         assert(k->second == "one");
     50         ++k;
     51         assert(k->first == 1);
     52         assert(k->second == "four");
     53         eq = c.equal_range(2);
     54         assert(std::distance(eq.first, eq.second) == 2);
     55         k = eq.first;
     56         assert(k->first == 2);
     57         assert(k->second == "two");
     58         ++k;
     59         assert(k->first == 2);
     60         assert(k->second == "four");
     61         eq = c.equal_range(3);
     62         assert(std::distance(eq.first, eq.second) == 1);
     63         k = eq.first;
     64         assert(k->first == 3);
     65         assert(k->second == "three");
     66         eq = c.equal_range(4);
     67         assert(std::distance(eq.first, eq.second) == 1);
     68         k = eq.first;
     69         assert(k->first == 4);
     70         assert(k->second == "four");
     71         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
     72         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
     73     }
     74 #if TEST_STD_VER >= 11
     75     {
     76         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
     77                             min_allocator<std::pair<const int, std::string>>> C;
     78         typedef std::pair<int, std::string> P;
     79         C c;
     80         c.insert(
     81                     {
     82                         P(1, "one"),
     83                         P(2, "two"),
     84                         P(3, "three"),
     85                         P(4, "four"),
     86                         P(1, "four"),
     87                         P(2, "four"),
     88                     }
     89                 );
     90         assert(c.size() == 6);
     91         typedef std::pair<C::iterator, C::iterator> Eq;
     92         Eq eq = c.equal_range(1);
     93         assert(std::distance(eq.first, eq.second) == 2);
     94         C::iterator k = eq.first;
     95         assert(k->first == 1);
     96         assert(k->second == "one");
     97         ++k;
     98         assert(k->first == 1);
     99         assert(k->second == "four");
    100         eq = c.equal_range(2);
    101         assert(std::distance(eq.first, eq.second) == 2);
    102         k = eq.first;
    103         assert(k->first == 2);
    104         assert(k->second == "two");
    105         ++k;
    106         assert(k->first == 2);
    107         assert(k->second == "four");
    108         eq = c.equal_range(3);
    109         assert(std::distance(eq.first, eq.second) == 1);
    110         k = eq.first;
    111         assert(k->first == 3);
    112         assert(k->second == "three");
    113         eq = c.equal_range(4);
    114         assert(std::distance(eq.first, eq.second) == 1);
    115         k = eq.first;
    116         assert(k->first == 4);
    117         assert(k->second == "four");
    118         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
    119         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
    120     }
    121 #endif
    122 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
    123 }
    124