libcxx

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

insert_init.pass.cpp (4088B)


      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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <unordered_map>
     13 
     14 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
     15 //           class Alloc = allocator<pair<const Key, T>>>
     16 // class unordered_multimap
     17 
     18 // void insert(initializer_list<value_type> il);
     19 
     20 #include <unordered_map>
     21 #include <string>
     22 #include <cassert>
     23 #include <cstddef>
     24 
     25 #include "test_iterators.h"
     26 #include "min_allocator.h"
     27 
     28 int main()
     29 {
     30     {
     31         typedef std::unordered_multimap<int, std::string> C;
     32         typedef std::pair<int, std::string> P;
     33         C c;
     34         c.insert(
     35                     {
     36                         P(1, "one"),
     37                         P(2, "two"),
     38                         P(3, "three"),
     39                         P(4, "four"),
     40                         P(1, "four"),
     41                         P(2, "four"),
     42                     }
     43                 );
     44         assert(c.size() == 6);
     45         typedef std::pair<C::iterator, C::iterator> Eq;
     46         Eq eq = c.equal_range(1);
     47         assert(std::distance(eq.first, eq.second) == 2);
     48         C::iterator k = eq.first;
     49         assert(k->first == 1);
     50         assert(k->second == "one");
     51         ++k;
     52         assert(k->first == 1);
     53         assert(k->second == "four");
     54         eq = c.equal_range(2);
     55         assert(std::distance(eq.first, eq.second) == 2);
     56         k = eq.first;
     57         assert(k->first == 2);
     58         assert(k->second == "two");
     59         ++k;
     60         assert(k->first == 2);
     61         assert(k->second == "four");
     62         eq = c.equal_range(3);
     63         assert(std::distance(eq.first, eq.second) == 1);
     64         k = eq.first;
     65         assert(k->first == 3);
     66         assert(k->second == "three");
     67         eq = c.equal_range(4);
     68         assert(std::distance(eq.first, eq.second) == 1);
     69         k = eq.first;
     70         assert(k->first == 4);
     71         assert(k->second == "four");
     72         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
     73         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
     74     }
     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 }