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