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_map<Key, T, Hash, Pred, Alloc>& x,
15//            const unordered_map<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_map<Key, T, Hash, Pred, Alloc>& x,
20//            const unordered_map<Key, T, Hash, Pred, Alloc>& y);
21
22#include <unordered_map>
23#include <string>
24#include <cassert>
25
26#include "min_allocator.h"
27
28int main()
29{
30    {
31        typedef std::unordered_map<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(30, "thirty"),
38            P(40, "fourty"),
39            P(50, "fifty"),
40            P(60, "sixty"),
41            P(70, "seventy"),
42            P(80, "eighty"),
43        };
44        const C c1(std::begin(a), std::end(a));
45        const C c2;
46        assert(!(c1 == c2));
47        assert( (c1 != c2));
48    }
49    {
50        typedef std::unordered_map<int, std::string> C;
51        typedef std::pair<int, std::string> P;
52        P a[] =
53        {
54            P(10, "ten"),
55            P(20, "twenty"),
56            P(30, "thirty"),
57            P(40, "fourty"),
58            P(50, "fifty"),
59            P(60, "sixty"),
60            P(70, "seventy"),
61            P(80, "eighty"),
62        };
63        const C c1(std::begin(a), std::end(a));
64        const C c2 = c1;
65        assert( (c1 == c2));
66        assert(!(c1 != c2));
67    }
68    {
69        typedef std::unordered_map<int, std::string> C;
70        typedef std::pair<int, std::string> P;
71        P a[] =
72        {
73            P(10, "ten"),
74            P(20, "twenty"),
75            P(30, "thirty"),
76            P(40, "fourty"),
77            P(50, "fifty"),
78            P(60, "sixty"),
79            P(70, "seventy"),
80            P(80, "eighty"),
81        };
82        C c1(std::begin(a), std::end(a));
83        C c2 = c1;
84        c2.rehash(30);
85        assert( (c1 == c2));
86        assert(!(c1 != c2));
87        c2.insert(P(90, "ninety"));
88        assert(!(c1 == c2));
89        assert( (c1 != c2));
90        c1.insert(P(90, "ninety"));
91        assert( (c1 == c2));
92        assert(!(c1 != c2));
93    }
94#if __cplusplus >= 201103L
95    {
96        typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
97                            min_allocator<std::pair<const int, std::string>>> C;
98        typedef std::pair<int, std::string> P;
99        P a[] =
100        {
101            P(10, "ten"),
102            P(20, "twenty"),
103            P(30, "thirty"),
104            P(40, "fourty"),
105            P(50, "fifty"),
106            P(60, "sixty"),
107            P(70, "seventy"),
108            P(80, "eighty"),
109        };
110        const C c1(std::begin(a), std::end(a));
111        const C c2;
112        assert(!(c1 == c2));
113        assert( (c1 != c2));
114    }
115    {
116        typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
117                            min_allocator<std::pair<const int, std::string>>> C;
118        typedef std::pair<int, std::string> P;
119        P a[] =
120        {
121            P(10, "ten"),
122            P(20, "twenty"),
123            P(30, "thirty"),
124            P(40, "fourty"),
125            P(50, "fifty"),
126            P(60, "sixty"),
127            P(70, "seventy"),
128            P(80, "eighty"),
129        };
130        const C c1(std::begin(a), std::end(a));
131        const C c2 = c1;
132        assert( (c1 == c2));
133        assert(!(c1 != c2));
134    }
135    {
136        typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
137                            min_allocator<std::pair<const int, std::string>>> C;
138        typedef std::pair<int, std::string> P;
139        P a[] =
140        {
141            P(10, "ten"),
142            P(20, "twenty"),
143            P(30, "thirty"),
144            P(40, "fourty"),
145            P(50, "fifty"),
146            P(60, "sixty"),
147            P(70, "seventy"),
148            P(80, "eighty"),
149        };
150        C c1(std::begin(a), std::end(a));
151        C c2 = c1;
152        c2.rehash(30);
153        assert( (c1 == c2));
154        assert(!(c1 != c2));
155        c2.insert(P(90, "ninety"));
156        assert(!(c1 == c2));
157        assert( (c1 != c2));
158        c1.insert(P(90, "ninety"));
159        assert( (c1 == c2));
160        assert(!(c1 != c2));
161    }
162#endif
163}
164