[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / unord / unord.map / unord.map.elem / at.pass.cpp
blobfe6ef8bc7e85cade5df17fe2d37cfb454c536602
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <unordered_map>
11 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
12 // class Alloc = allocator<pair<const Key, T>>>
13 // class unordered_map
15 // mapped_type& at(const key_type& k);
16 // const mapped_type& at(const key_type& k) const;
18 #include <cassert>
19 #include <stdexcept>
20 #include <string>
21 #include <unordered_map>
23 #include "MoveOnly.h"
24 #include "min_allocator.h"
25 #include "test_macros.h"
27 int main(int, char**)
30 typedef std::unordered_map<int, std::string> C;
31 typedef std::pair<int, std::string> P;
32 P a[] =
34 P(1, "one"),
35 P(2, "two"),
36 P(3, "three"),
37 P(4, "four"),
38 P(1, "four"),
39 P(2, "four"),
41 C c(a, a + sizeof(a)/sizeof(a[0]));
42 assert(c.size() == 4);
43 c.at(1) = "ONE";
44 assert(c.at(1) == "ONE");
45 #ifndef TEST_HAS_NO_EXCEPTIONS
46 try
48 c.at(11) = "eleven";
49 assert(false);
51 catch (std::out_of_range&)
54 assert(c.size() == 4);
55 #endif
58 typedef std::unordered_map<int, std::string> C;
59 typedef std::pair<int, std::string> P;
60 P a[] =
62 P(1, "one"),
63 P(2, "two"),
64 P(3, "three"),
65 P(4, "four"),
66 P(1, "four"),
67 P(2, "four"),
69 const C c(a, a + sizeof(a)/sizeof(a[0]));
70 assert(c.size() == 4);
71 assert(c.at(1) == "one");
72 #ifndef TEST_HAS_NO_EXCEPTIONS
73 try
75 TEST_IGNORE_NODISCARD c.at(11);
76 assert(false);
78 catch (std::out_of_range&)
81 assert(c.size() == 4);
82 #endif
84 #if TEST_STD_VER >= 11
86 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
87 min_allocator<std::pair<const int, std::string>>> C;
88 typedef std::pair<int, std::string> P;
89 P a[] =
91 P(1, "one"),
92 P(2, "two"),
93 P(3, "three"),
94 P(4, "four"),
95 P(1, "four"),
96 P(2, "four"),
98 C c(a, a + sizeof(a)/sizeof(a[0]));
99 assert(c.size() == 4);
100 c.at(1) = "ONE";
101 assert(c.at(1) == "ONE");
102 #ifndef TEST_HAS_NO_EXCEPTIONS
105 c.at(11) = "eleven";
106 assert(false);
108 catch (std::out_of_range&)
111 assert(c.size() == 4);
112 #endif
115 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
116 min_allocator<std::pair<const int, std::string>>> C;
117 typedef std::pair<int, std::string> P;
118 P a[] =
120 P(1, "one"),
121 P(2, "two"),
122 P(3, "three"),
123 P(4, "four"),
124 P(1, "four"),
125 P(2, "four"),
127 const C c(a, a + sizeof(a)/sizeof(a[0]));
128 assert(c.size() == 4);
129 assert(c.at(1) == "one");
130 #ifndef TEST_HAS_NO_EXCEPTIONS
133 TEST_IGNORE_NODISCARD c.at(11);
134 assert(false);
136 catch (std::out_of_range&)
139 assert(c.size() == 4);
140 #endif
142 #endif
144 return 0;