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 // iterator       begin()        {return __table_.begin();}
17 // iterator       end()          {return __table_.end();}
18 // const_iterator begin()  const {return __table_.begin();}
19 // const_iterator end()    const {return __table_.end();}
20 // const_iterator cbegin() const {return __table_.begin();}
21 // const_iterator cend()   const {return __table_.end();}
22 
23 #include <unordered_map>
24 #include <string>
25 #include <cassert>
26 #include <cstddef>
27 
28 #include "test_macros.h"
29 #include "min_allocator.h"
30 
main()31 int main()
32 {
33     {
34         typedef std::unordered_multimap<int, std::string> C;
35         typedef std::pair<int, std::string> P;
36         P a[] =
37         {
38             P(1, "one"),
39             P(2, "two"),
40             P(3, "three"),
41             P(4, "four"),
42             P(1, "four"),
43             P(2, "four"),
44         };
45         C c(a, a + sizeof(a)/sizeof(a[0]));
46         assert(c.bucket_count() >= 7);
47         assert(c.size() == 6);
48         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
49         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
50         C::iterator i;
51         i = c.begin();
52         i->second = "ONE";
53         assert(i->second == "ONE");
54     }
55     {
56         typedef std::unordered_multimap<int, std::string> C;
57         typedef std::pair<int, std::string> P;
58         P a[] =
59         {
60             P(1, "one"),
61             P(2, "two"),
62             P(3, "three"),
63             P(4, "four"),
64             P(1, "four"),
65             P(2, "four"),
66         };
67         const C c(a, a + sizeof(a)/sizeof(a[0]));
68         assert(c.bucket_count() >= 7);
69         assert(c.size() == 6);
70         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
71         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
72         C::const_iterator i;
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         P a[] =
80         {
81             P(1, "one"),
82             P(2, "two"),
83             P(3, "three"),
84             P(4, "four"),
85             P(1, "four"),
86             P(2, "four"),
87         };
88         C c(a, a + sizeof(a)/sizeof(a[0]));
89         assert(c.bucket_count() >= 7);
90         assert(c.size() == 6);
91         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
92         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
93         C::iterator i;
94         i = c.begin();
95         i->second = "ONE";
96         assert(i->second == "ONE");
97     }
98     {
99         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
100                             min_allocator<std::pair<const int, std::string>>> C;
101         typedef std::pair<int, std::string> P;
102         P a[] =
103         {
104             P(1, "one"),
105             P(2, "two"),
106             P(3, "three"),
107             P(4, "four"),
108             P(1, "four"),
109             P(2, "four"),
110         };
111         const C c(a, a + sizeof(a)/sizeof(a[0]));
112         assert(c.bucket_count() >= 7);
113         assert(c.size() == 6);
114         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
115         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
116         C::const_iterator i;
117     }
118 #endif
119 #if TEST_STD_VER > 11
120     { // N3644 testing
121         typedef std::unordered_multimap<int,double> C;
122         C::iterator ii1{}, ii2{};
123         C::iterator ii4 = ii1;
124         C::const_iterator cii{};
125         assert ( ii1 == ii2 );
126         assert ( ii1 == ii4 );
127 
128         assert (!(ii1 != ii2 ));
129 
130         assert ( (ii1 == cii ));
131         assert ( (cii == ii1 ));
132         assert (!(ii1 != cii ));
133         assert (!(cii != ii1 ));
134     }
135 #endif
136 }
137