blob: c072248f866afcd3e97da92850be8c300621595f [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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// mapped_type& operator[](const key_type& k);
17
18#include <unordered_map>
19#include <string>
20#include <cassert>
21
Marshall Clowdf00d5e2015-01-28 21:22:53 +000022#include "MoveOnly.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000023#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000024
25int main()
26{
27 {
28 typedef std::unordered_map<int, std::string> C;
29 typedef std::pair<int, std::string> P;
30 P a[] =
31 {
32 P(1, "one"),
33 P(2, "two"),
34 P(3, "three"),
35 P(4, "four"),
36 P(1, "four"),
37 P(2, "four"),
38 };
39 C c(a, a + sizeof(a)/sizeof(a[0]));
40 assert(c.size() == 4);
41 c[1] = "ONE";
42 assert(c.at(1) == "ONE");
43 c[11] = "eleven";
44 assert(c.size() == 5);
45 assert(c.at(11) == "eleven");
46 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070047#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000048 {
49 typedef std::unordered_map<MoveOnly, std::string> C;
50 typedef std::pair<int, std::string> P;
51 P a[] =
52 {
53 P(1, "one"),
54 P(2, "two"),
55 P(3, "three"),
56 P(4, "four"),
57 P(1, "four"),
58 P(2, "four"),
59 };
60 C c(a, a + sizeof(a)/sizeof(a[0]));
61 assert(c.size() == 4);
62 c[1] = "ONE";
63 assert(c.at(1) == "ONE");
64 c[11] = "eleven";
65 assert(c.size() == 5);
66 assert(c.at(11) == "eleven");
67 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070068#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
69#if __cplusplus >= 201103L
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +000070 {
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.size() == 4);
85 c[1] = "ONE";
86 assert(c.at(1) == "ONE");
87 c[11] = "eleven";
88 assert(c.size() == 5);
89 assert(c.at(11) == "eleven");
90 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070091#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +000092 {
93 typedef std::unordered_map<MoveOnly, std::string, std::hash<MoveOnly>, std::equal_to<MoveOnly>,
94 min_allocator<std::pair<const MoveOnly, std::string>>> C;
95 typedef std::pair<int, std::string> P;
96 P a[] =
97 {
98 P(1, "one"),
99 P(2, "two"),
100 P(3, "three"),
101 P(4, "four"),
102 P(1, "four"),
103 P(2, "four"),
104 };
105 C c(a, a + sizeof(a)/sizeof(a[0]));
106 assert(c.size() == 4);
107 c[1] = "ONE";
108 assert(c.at(1) == "ONE");
109 c[11] = "eleven";
110 assert(c.size() == 5);
111 assert(c.at(11) == "eleven");
112 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700113#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000114#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000115}