Home | History | Annotate | Download | only in unord.multimap
      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, class Pred, class Alloc>
     13 // bool
     14 // operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
     15 //            const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
     16 //
     17 // template <class Key, class T, class Hash, class Pred, class Alloc>
     18 // bool
     19 // operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
     20 //            const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
     21 
     22 #include <unordered_map>
     23 #include <string>
     24 #include <cassert>
     25 
     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         P a[] =
     34         {
     35             P(10, "ten"),
     36             P(20, "twenty"),
     37             P(20, "twenty 2"),
     38             P(30, "thirty"),
     39             P(40, "forty"),
     40             P(50, "fifty"),
     41             P(50, "fifty 2"),
     42             P(50, "fifty 3"),
     43             P(60, "sixty"),
     44             P(70, "seventy"),
     45             P(80, "eighty"),
     46         };
     47         const C c1(std::begin(a), std::end(a));
     48         const C c2;
     49         assert(!(c1 == c2));
     50         assert( (c1 != c2));
     51     }
     52     {
     53         typedef std::unordered_multimap<int, std::string> C;
     54         typedef std::pair<int, std::string> P;
     55         P a[] =
     56         {
     57             P(10, "ten"),
     58             P(20, "twenty"),
     59             P(20, "twenty 2"),
     60             P(30, "thirty"),
     61             P(40, "forty"),
     62             P(50, "fifty"),
     63             P(50, "fifty 2"),
     64             P(50, "fifty 3"),
     65             P(60, "sixty"),
     66             P(70, "seventy"),
     67             P(80, "eighty"),
     68         };
     69         const C c1(std::begin(a), std::end(a));
     70         const C c2 = c1;
     71         assert( (c1 == c2));
     72         assert(!(c1 != c2));
     73     }
     74     {
     75         typedef std::unordered_multimap<int, std::string> C;
     76         typedef std::pair<int, std::string> P;
     77         P a[] =
     78         {
     79             P(10, "ten"),
     80             P(20, "twenty"),
     81             P(20, "twenty 2"),
     82             P(30, "thirty"),
     83             P(40, "forty"),
     84             P(50, "fifty"),
     85             P(50, "fifty 2"),
     86             P(50, "fifty 3"),
     87             P(60, "sixty"),
     88             P(70, "seventy"),
     89             P(80, "eighty"),
     90         };
     91         C c1(std::begin(a), std::end(a));
     92         C c2 = c1;
     93         c2.rehash(30);
     94         assert( (c1 == c2));
     95         assert(!(c1 != c2));
     96         c2.insert(P(90, "ninety"));
     97         assert(!(c1 == c2));
     98         assert( (c1 != c2));
     99         c1.insert(P(90, "ninety"));
    100         assert( (c1 == c2));
    101         assert(!(c1 != c2));
    102     }
    103 #if __cplusplus >= 201103L
    104     {
    105         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
    106                             min_allocator<std::pair<const int, std::string>>> C;
    107         typedef std::pair<int, std::string> P;
    108         P a[] =
    109         {
    110             P(10, "ten"),
    111             P(20, "twenty"),
    112             P(20, "twenty 2"),
    113             P(30, "thirty"),
    114             P(40, "forty"),
    115             P(50, "fifty"),
    116             P(50, "fifty 2"),
    117             P(50, "fifty 3"),
    118             P(60, "sixty"),
    119             P(70, "seventy"),
    120             P(80, "eighty"),
    121         };
    122         const C c1(std::begin(a), std::end(a));
    123         const C c2;
    124         assert(!(c1 == c2));
    125         assert( (c1 != c2));
    126     }
    127     {
    128         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
    129                             min_allocator<std::pair<const int, std::string>>> C;
    130         typedef std::pair<int, std::string> P;
    131         P a[] =
    132         {
    133             P(10, "ten"),
    134             P(20, "twenty"),
    135             P(20, "twenty 2"),
    136             P(30, "thirty"),
    137             P(40, "forty"),
    138             P(50, "fifty"),
    139             P(50, "fifty 2"),
    140             P(50, "fifty 3"),
    141             P(60, "sixty"),
    142             P(70, "seventy"),
    143             P(80, "eighty"),
    144         };
    145         const C c1(std::begin(a), std::end(a));
    146         const C c2 = c1;
    147         assert( (c1 == c2));
    148         assert(!(c1 != c2));
    149     }
    150     {
    151         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
    152                             min_allocator<std::pair<const int, std::string>>> C;
    153         typedef std::pair<int, std::string> P;
    154         P a[] =
    155         {
    156             P(10, "ten"),
    157             P(20, "twenty"),
    158             P(20, "twenty 2"),
    159             P(30, "thirty"),
    160             P(40, "forty"),
    161             P(50, "fifty"),
    162             P(50, "fifty 2"),
    163             P(50, "fifty 3"),
    164             P(60, "sixty"),
    165             P(70, "seventy"),
    166             P(80, "eighty"),
    167         };
    168         C c1(std::begin(a), std::end(a));
    169         C c2 = c1;
    170         c2.rehash(30);
    171         assert( (c1 == c2));
    172         assert(!(c1 != c2));
    173         c2.insert(P(90, "ninety"));
    174         assert(!(c1 == c2));
    175         assert( (c1 != c2));
    176         c1.insert(P(90, "ninety"));
    177         assert( (c1 == c2));
    178         assert(!(c1 != c2));
    179     }
    180 #endif
    181 }
    182