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